fix: Add missing logger.js and fix Ollama routes middleware
- Add backend/src/utils/logger.js (Winston logger) - Fix ollama.routes.js middleware import (requireAuth instead of isAuthenticated) - Add axios to package.json dependencies - Create logs directory for Winston - Fix module paths for Ollama integration This fixes the backend startup issues after Ollama integration.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const ollamaController = require('../controllers/ollama.controller');
|
||||
const { isAuthenticated } = require('../middleware/auth.middleware');
|
||||
const { requireAuth } = require('../middlewares/auth');
|
||||
|
||||
// All routes require authentication
|
||||
router.use(isAuthenticated);
|
||||
router.use(requireAuth);
|
||||
|
||||
// Test Ollama connection
|
||||
router.get('/test', ollamaController.testConnection);
|
||||
|
||||
43
backend/src/utils/logger.js
Normal file
43
backend/src/utils/logger.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const winston = require('winston');
|
||||
const path = require('path');
|
||||
|
||||
// Log format
|
||||
const logFormat = winston.format.combine(
|
||||
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
||||
winston.format.errors({ stack: true }),
|
||||
winston.format.printf(({ timestamp, level, message, stack }) => {
|
||||
return `${timestamp} [${level.toUpperCase()}]: ${stack || message}`;
|
||||
})
|
||||
);
|
||||
|
||||
// Logger instance
|
||||
const logger = winston.createLogger({
|
||||
level: process.env.LOG_LEVEL || 'info',
|
||||
format: logFormat,
|
||||
transports: [
|
||||
// Console transport
|
||||
new winston.transports.Console({
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
logFormat
|
||||
),
|
||||
}),
|
||||
// File transport - errors
|
||||
new winston.transports.File({
|
||||
filename: path.join(__dirname, '../../logs/error.log'),
|
||||
level: 'error',
|
||||
maxsize: 5242880, // 5MB
|
||||
maxFiles: 5,
|
||||
}),
|
||||
// File transport - combined
|
||||
new winston.transports.File({
|
||||
filename: path.join(__dirname, '../../logs/combined.log'),
|
||||
maxsize: 5242880, // 5MB
|
||||
maxFiles: 5,
|
||||
}),
|
||||
],
|
||||
exitOnError: false,
|
||||
});
|
||||
|
||||
module.exports = logger;
|
||||
|
||||
Reference in New Issue
Block a user