WIP: OMNL compliance console, relay rpc pool, zedxion relay service
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import express, { Express, Request, Response, NextFunction } from 'express';
|
||||
import express, { Express, Request, Response, NextFunction, type RequestHandler } from 'express';
|
||||
import { Server } from 'http';
|
||||
import path from 'path';
|
||||
import { readFileSync, existsSync } from 'fs';
|
||||
@@ -91,8 +91,8 @@ export class ApiServer {
|
||||
// CORS
|
||||
this.app.use(cors());
|
||||
|
||||
// Compression
|
||||
this.app.use(compression());
|
||||
// Compression (Express 5 typings — runtime-compatible)
|
||||
this.app.use(compression() as unknown as RequestHandler);
|
||||
|
||||
// Body parsing
|
||||
this.app.use(express.json());
|
||||
@@ -114,10 +114,12 @@ export class ApiServer {
|
||||
|
||||
const publicPath = path.join(__dirname, '../../public');
|
||||
if (existsSync(publicPath)) {
|
||||
this.app.use('/static', express.static(publicPath, {
|
||||
const staticOpts = {
|
||||
immutable: true,
|
||||
maxAge: '1d',
|
||||
}));
|
||||
} as const;
|
||||
this.app.use('/static', express.static(publicPath, staticOpts));
|
||||
this.app.use('/omnl/static', express.static(publicPath, staticOpts));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,16 +149,31 @@ export class ApiServer {
|
||||
});
|
||||
|
||||
const dashboardPath = path.join(__dirname, '../../public/omnl-dashboard.html');
|
||||
this.app.get('/omnl/dashboard', (req: Request, res: Response) => {
|
||||
const complianceConsolePath = path.join(__dirname, '../../public/omnl-compliance-console.html');
|
||||
|
||||
const authorizeOmnlHtml = (req: Request, res: Response): boolean => {
|
||||
const tok = process.env.OMNL_DASHBOARD_TOKEN?.trim();
|
||||
if (tok) {
|
||||
const q = String(req.query.access_token ?? '').trim();
|
||||
const h = String(req.headers['x-omnl-dashboard-token'] ?? '').trim();
|
||||
if (q !== tok && h !== tok) {
|
||||
res.status(401).type('text/plain').send('Unauthorized: set access_token query or X-OMNL-Dashboard-Token header');
|
||||
return;
|
||||
}
|
||||
if (!tok) return true;
|
||||
const q = String(req.query.access_token ?? '').trim();
|
||||
const h = String(req.headers['x-omnl-dashboard-token'] ?? '').trim();
|
||||
if (q !== tok && h !== tok) {
|
||||
res.status(401).type('text/plain').send('Unauthorized: set access_token query or X-OMNL-Dashboard-Token header');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
this.app.get('/omnl/compliance', (req: Request, res: Response) => {
|
||||
if (!authorizeOmnlHtml(req, res)) return;
|
||||
if (!existsSync(complianceConsolePath)) {
|
||||
res.status(404).type('text/plain').send('omnl-compliance-console.html missing');
|
||||
return;
|
||||
}
|
||||
res.type('html').send(readFileSync(complianceConsolePath, 'utf8'));
|
||||
});
|
||||
|
||||
this.app.get('/omnl/dashboard', (req: Request, res: Response) => {
|
||||
if (!authorizeOmnlHtml(req, res)) return;
|
||||
if (!existsSync(dashboardPath)) {
|
||||
res.status(404).type('text/plain').send('omnl-dashboard.html missing');
|
||||
return;
|
||||
@@ -210,9 +227,9 @@ export class ApiServer {
|
||||
this.app.use('/api/v1', aggregatorRouteMatrixRoutes);
|
||||
this.app.use('/api/v1', partnerPayloadRoutes);
|
||||
this.app.use('/api/v1', checkpointRoutes);
|
||||
this.app.use('/api/v1', omnlComplianceRoutes);
|
||||
this.app.use('/api/v1', omnlRoutes);
|
||||
this.app.use('/api/v1', omnlIpsasRoutes);
|
||||
this.app.use('/api/v1', omnlComplianceRoutes);
|
||||
this.app.use('/api/v2', plannerV2Routes);
|
||||
|
||||
// Admin routes (stricter rate limit)
|
||||
|
||||
Reference in New Issue
Block a user