u
This commit is contained in:
@@ -18,6 +18,7 @@ import { shutdownJavascriptSandboxWorkers } from '../services/javascriptSandbox.
|
||||
import { getOrCreateCert } from '../util/cert.js';
|
||||
import { createLogger } from '../util/logger.js';
|
||||
import v1Router from '../v1/index.js';
|
||||
import { agentRouter } from './agent/index.js';
|
||||
import { startBackendMonitor, stopBackendMonitor, isDevMode } from '../backendmonitor/server.js';
|
||||
import { startBackupService, stopBackupService } from '../services/backupService.js';
|
||||
import { startHealthMonitorService, stopHealthMonitorService } from '../services/healthMonitorService.js';
|
||||
@@ -100,6 +101,20 @@ function corsMiddleware(req, res, next) {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (req.path.startsWith('/api/agent')) {
|
||||
res.setHeader('Access-Control-Allow-Origin', origin || '*');
|
||||
const reqHeaders = req.headers['access-control-request-headers'];
|
||||
res.setHeader(
|
||||
'Access-Control-Allow-Headers',
|
||||
reqHeaders || 'Content-Type, Authorization, x-agent-token, x-auth-token, authtoken, auth-token, token, x-token, agentversion, clientversion, version'
|
||||
);
|
||||
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,PATCH,DELETE,OPTIONS');
|
||||
if (req.method === 'OPTIONS') {
|
||||
return res.sendStatus(204);
|
||||
}
|
||||
return next();
|
||||
}
|
||||
|
||||
if (req.path.startsWith('/v1')) {
|
||||
if (origin) {
|
||||
res.setHeader('Access-Control-Allow-Origin', origin);
|
||||
@@ -144,7 +159,7 @@ export async function buildApiApp() {
|
||||
|
||||
app.use((req, res, next) => {
|
||||
// Do not attach no-store to SSE or public endpoints
|
||||
if (req.path !== '/api/events' && !req.path.startsWith('/api/public') && !req.path.startsWith('/public')) {
|
||||
if (req.path !== '/api/events' && !req.path.endsWith('/events') && !req.path.startsWith('/api/public') && !req.path.startsWith('/public')) {
|
||||
res.setHeader('Cache-Control', 'no-store');
|
||||
}
|
||||
next();
|
||||
@@ -164,6 +179,7 @@ export async function buildApiApp() {
|
||||
}
|
||||
|
||||
app.routeCount = await registerRoutes(app, '/api');
|
||||
app.use('/api/agent', agentRouter);
|
||||
app.use('/api/v1', v1Router);
|
||||
|
||||
app.use((_req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user