fix: proxy without channel prefix for SREBOT, revert server.js rewrite
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
|
||||
// Simulate our auth middleware (mounted at /api like the real one)
|
||||
app.use('/api', (req, res, next) => {
|
||||
console.log('[auth] req.url:', req.url, 'req.path:', req.path);
|
||||
next();
|
||||
});
|
||||
|
||||
// Our rewrite middleware (no mount path)
|
||||
app.use((req, res, next) => {
|
||||
console.log('[rewrite_before] req.url:', req.url, 'req.path:', req.path, 'req.originalUrl:', req.originalUrl);
|
||||
if (req.url.startsWith('/api/sre')) {
|
||||
req.url = '/api' + req.url.slice(9);
|
||||
console.log('[rewrite_after] req.url:', req.url, 'req.path:', req.path);
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
// Route handler
|
||||
app.get('/api/info', (req, res) => {
|
||||
console.log('[handler] req.url:', req.url, 'req.path:', req.path);
|
||||
res.json({ ok: true, url: req.url, path: req.path });
|
||||
});
|
||||
|
||||
// 404 handler
|
||||
app.use((req, res) => {
|
||||
console.log('[404] req.url:', req.url, 'req.path:', req.path);
|
||||
res.status(404).json({ error: 'not found' });
|
||||
});
|
||||
|
||||
app.listen(6001, () => {
|
||||
console.log('Listening on 6001');
|
||||
// Make a test request to ourselves
|
||||
const http = require('http');
|
||||
http.get('http://127.0.0.1:6001/api/sre/info', (res) => {
|
||||
let data = '';
|
||||
res.on('data', c => data += c);
|
||||
res.on('end', () => {
|
||||
console.log('Response:', data);
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -88,13 +88,7 @@ function requireAdminBearer(req, res, next) {
|
||||
|
||||
app.use('/api', requireApiBearer);
|
||||
|
||||
// Rewrite /api/sre/* → /api/* so the gateway can forward channel-prefixed paths.
|
||||
app.use((req, res, next) => {
|
||||
if (req.url.startsWith('/api/sre')) {
|
||||
req.url = '/api' + req.url.slice(8);
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
// Readiness gate: heavy aggregation endpoints sit behind this so cold-start
|
||||
// requests don't pile up on the read connection while the DB is still opening
|
||||
|
||||
Reference in New Issue
Block a user