Skip to content

Commit 1711c84

Browse files
committed
fix: router
1 parent 895a6d4 commit 1711c84

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

β€ŽDockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ EXPOSE 3000
2323
ENV NODE_ENV=production
2424
ENV PORT=3000
2525
ENV HOST=0.0.0.0
26+
ENV VERBOSE=true
2627

27-
# Start the application
28-
CMD ["node", "dist/index.js","-v"]
28+
# Start the application with verbose logging enabled
29+
CMD ["node", "dist/index.js"]

β€Žsrc/app.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,48 @@ app.use(express.urlencoded({ extended: true }));
1818
app.use((req, res, next) => {
1919
if (global.verboseLogging) {
2020
console.log(`${new Date().toISOString()} - ${req.method} ${req.path}`);
21+
console.log(`Original URL: ${req.originalUrl}`);
22+
console.log(`Base URL: ${req.baseUrl}`);
2123
if (req.body && Object.keys(req.body).length > 0) {
2224
console.log('Request body:', JSON.stringify(req.body, null, 2));
2325
}
2426
}
2527
next();
2628
});
2729

30+
// Add a simple root endpoint for debugging
31+
app.get('/', (req, res) => {
32+
res.json({
33+
message: 'Mock OpenAI API Server',
34+
status: 'running',
35+
timestamp: new Date().toISOString(),
36+
availableEndpoints: [
37+
'GET /health',
38+
'GET /v1/models',
39+
'POST /v1/chat/completions',
40+
'POST /v1/images/generations'
41+
]
42+
});
43+
});
44+
2845
// Routes
2946
app.use('/', routes);
3047

3148
// 404 handler
3249
app.use((req, res) => {
50+
if (global.verboseLogging) {
51+
console.log(`404 - Path not found: ${req.originalUrl}`);
52+
console.log(`Method: ${req.method}`);
53+
console.log(`Headers:`, req.headers);
54+
}
3355
res.status(404).json({
3456
error: {
3557
message: `Path not found: ${req.originalUrl}`,
3658
type: 'not_found_error',
37-
code: 'path_not_found'
59+
code: 'path_not_found',
60+
method: req.method,
61+
path: req.path,
62+
originalUrl: req.originalUrl
3863
}
3964
});
4065
});

β€Žsrc/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import app from './app';
55
const PORT = process.env.PORT || 3000;
66
const HOST = process.env.HOST || '0.0.0.0';
77

8+
// Enable verbose logging by default in development or when VERBOSE is set
9+
global.verboseLogging = process.env.NODE_ENV !== 'production' || process.env.VERBOSE === 'true';
10+
811
app.listen(PORT, () => {
912
console.log(`πŸš€ Mock OpenAI API server started successfully!`);
1013
console.log(`πŸ“ Server address: http://${HOST}:${PORT}`);
14+
console.log(`πŸ” Verbose logging: ${global.verboseLogging ? 'enabled' : 'disabled'}`);
1115
console.log(`πŸ“– API Documentation:`);
1216
console.log(` β€’ GET /health - Health check`);
1317
console.log(` β€’ GET /v1/models - Get model list`);

β€Žsrc/routes/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import {
88

99
const router = Router();
1010

11+
// Debug middleware to log all requests to this router
12+
router.use((req, res, next) => {
13+
if (global.verboseLogging) {
14+
console.log(`Router - ${req.method} ${req.path} (originalUrl: ${req.originalUrl})`);
15+
}
16+
next();
17+
});
18+
1119
// Health check endpoint
1220
router.get('/health', handleHealthCheck);
1321

0 commit comments

Comments
Β (0)