diff --git a/backend/package.json b/backend/package.json index e2a6aa9..2c2e0e4 100644 --- a/backend/package.json +++ b/backend/package.json @@ -18,6 +18,7 @@ "author": "", "license": "MIT", "dependencies": { + "axios": "^1.13.2", "bcrypt": "^5.1.1", "connect-sqlite3": "^0.9.16", "cors": "^2.8.5", diff --git a/backend/src/routes/ollama.routes.js b/backend/src/routes/ollama.routes.js index fb659cc..80a6d67 100644 --- a/backend/src/routes/ollama.routes.js +++ b/backend/src/routes/ollama.routes.js @@ -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); diff --git a/backend/src/utils/logger.js b/backend/src/utils/logger.js new file mode 100644 index 0000000..20729b4 --- /dev/null +++ b/backend/src/utils/logger.js @@ -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; +