diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 1ac59ec9..e798a5f5 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -63,6 +63,13 @@ jobs: run: npm run lint # Run the linter to check for code quality issues. continue-on-error: true # Allows the workflow to proceed even if linting fails. + - name: Stop Production Server Before Tests + # This is a critical step to ensure a clean test environment. + # It stops the currently running pm2 process, freeing up port 3001 so that the + # integration test suite can launch its own, fresh server instance. + # '|| true' ensures the workflow doesn't fail if the process isn't running. + run: pm2 stop flyer-crawler-api || true + - name: Run All Tests and Generate Merged Coverage Report # This single step runs both unit and integration tests, then merges their # coverage data into a single report. It combines the environment variables diff --git a/package-lock.json b/package-lock.json index 601dacb4..ea5a92cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "cookie-parser": "^1.4.7", "date-fns": "^4.1.0", "express": "^5.1.0", + "express-list-endpoints": "^7.1.1", "express-rate-limit": "^8.2.1", "jsonwebtoken": "^9.0.2", "multer": "^2.0.2", @@ -7595,6 +7596,15 @@ "url": "https://opencollective.com/express" } }, + "node_modules/express-list-endpoints": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/express-list-endpoints/-/express-list-endpoints-7.1.1.tgz", + "integrity": "sha512-SA6YHH1r6DrioJ4fFJNqiwu1FweGFqJZO9KBApMzwPosoSGPOX2AW0wiMepOXjojjEXDuP9whIvckomheErbJA==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/express-rate-limit": { "version": "8.2.1", "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.2.1.tgz", diff --git a/package.json b/package.json index 326c0287..7a64a100 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "cookie-parser": "^1.4.7", "date-fns": "^4.1.0", "express": "^5.1.0", + "express-list-endpoints": "^7.1.1", "express-rate-limit": "^8.2.1", "jsonwebtoken": "^9.0.2", "multer": "^2.0.2", diff --git a/server.ts b/server.ts index 55b86c23..271f310e 100644 --- a/server.ts +++ b/server.ts @@ -1,6 +1,7 @@ // server.ts import express, { Request, Response, NextFunction } from 'express'; import cookieParser from 'cookie-parser'; +import listEndpoints from 'express-list-endpoints'; import { getPool } from './src/services/db/connection'; import passport from './src/routes/passport'; @@ -51,11 +52,6 @@ app.use(express.urlencoded({ limit: '100mb', extended: true })); app.use(cookieParser()); // Middleware to parse cookies app.use(passport.initialize()); // Initialize Passport -// --- RAW REQUEST LOGGER --- -app.use((req, res, next) => { - console.log(`[RAW INCOMING REQUEST] Method: ${req.method}, URL: ${req.originalUrl}`); - next(); -}); // --- Logging Middleware --- @@ -127,24 +123,7 @@ app.listen(PORT, () => { logger.info(`Authentication server started on port ${PORT}`); }); -// --- START ROUTE DEBUGGING --- -// On server startup, print all registered routes to the console. -// This helps debug 404s by showing exactly what Express thinks the routes are. -const routes: { method: string, path: string }[] = []; -app._router.stack.forEach((middleware: any) => { - if (middleware.route) { // routes registered directly on the app - routes.push({ - method: Object.keys(middleware.route.methods).join(', ').toUpperCase(), - path: middleware.route.path - }); - } else if (middleware.name === 'router') { // router instances - middleware.handle.stack.forEach((handler: any) => { - const route = handler.route; - route && routes.push({ method: Object.keys(route.methods).join(', ').toUpperCase(), path: `${middleware.regexp.source.replace('\\/?(?=\\/|$)', '').slice(1)}${route.path}`}); - }); - } -}); console.log('--- REGISTERED API ROUTES ---'); -console.table(routes); +console.table(listEndpoints(app)); console.log('-----------------------------'); // --- END ROUTE DEBUGGING --- \ No newline at end of file