chore: .gitignore and README updates
Made-with: Cursor
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import express, { Express, Request, Response, NextFunction } from 'express';
|
||||
import path from 'path';
|
||||
import { readFileSync, existsSync } from 'fs';
|
||||
import cors from 'cors';
|
||||
import compression from 'compression';
|
||||
import { apiRateLimiter, strictRateLimiter } from './middleware/rate-limit';
|
||||
@@ -15,7 +17,10 @@ import arbitrageRoutes from './routes/arbitrage';
|
||||
import aggregatorRouteMatrixRoutes from './routes/aggregator-routes';
|
||||
import partnerPayloadRoutes from './routes/partner-payloads';
|
||||
import plannerV2Routes from './routes/planner-v2';
|
||||
import omnlRoutes from './routes/omnl';
|
||||
import omnlIpsasRoutes from './routes/omnl-ipsas';
|
||||
import { MultiChainIndexer } from '../indexer/chain-indexer';
|
||||
import { OmnlEventPoller } from '../indexer/omnl-event-poller';
|
||||
import { getDatabasePool } from '../database/client';
|
||||
import winston from 'winston';
|
||||
|
||||
@@ -42,6 +47,7 @@ export class ApiServer {
|
||||
private port: number;
|
||||
private indexerEnabled: boolean;
|
||||
private indexer: MultiChainIndexer | null;
|
||||
private omnlPoller: OmnlEventPoller | null;
|
||||
|
||||
private resolveTrustProxySetting(): boolean | number | string {
|
||||
const raw = (process.env.EXPRESS_TRUST_PROXY ?? process.env.TRUST_PROXY ?? '1').trim();
|
||||
@@ -58,6 +64,7 @@ export class ApiServer {
|
||||
this.port = parseInt(process.env.PORT || '3000', 10);
|
||||
this.indexerEnabled = this.resolveFeatureFlag('ENABLE_INDEXER', true);
|
||||
this.indexer = this.indexerEnabled ? new MultiChainIndexer() : null;
|
||||
this.omnlPoller = this.resolveFeatureFlag('ENABLE_OMNL_EVENT_POLLER', false) ? new OmnlEventPoller() : null;
|
||||
|
||||
this.setupMiddleware();
|
||||
this.setupRoutes();
|
||||
@@ -126,6 +133,24 @@ export class ApiServer {
|
||||
}
|
||||
});
|
||||
|
||||
const dashboardPath = path.join(__dirname, '../../public/omnl-dashboard.html');
|
||||
this.app.get('/omnl/dashboard', (req: Request, res: Response) => {
|
||||
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 (!existsSync(dashboardPath)) {
|
||||
res.status(404).type('text/plain').send('omnl-dashboard.html missing');
|
||||
return;
|
||||
}
|
||||
res.type('html').send(readFileSync(dashboardPath, 'utf8'));
|
||||
});
|
||||
|
||||
// API routes
|
||||
this.app.use('/api/v1', tokenRoutes);
|
||||
this.app.use('/api/v1', configRoutes);
|
||||
@@ -138,6 +163,8 @@ export class ApiServer {
|
||||
this.app.use('/api/v1', arbitrageRoutes);
|
||||
this.app.use('/api/v1', aggregatorRouteMatrixRoutes);
|
||||
this.app.use('/api/v1', partnerPayloadRoutes);
|
||||
this.app.use('/api/v1', omnlRoutes);
|
||||
this.app.use('/api/v1', omnlIpsasRoutes);
|
||||
this.app.use('/api/v2', plannerV2Routes);
|
||||
|
||||
// Admin routes (stricter rate limit)
|
||||
@@ -152,6 +179,9 @@ export class ApiServer {
|
||||
health: '/health',
|
||||
api: '/api/v1',
|
||||
apiV2: '/api/v2',
|
||||
omnlOpenApi: '/api/v1/omnl/openapi.json',
|
||||
omnlCatalog: '/api/v1/omnl/catalog',
|
||||
omnlDashboard: '/omnl/dashboard',
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -183,6 +213,8 @@ export class ApiServer {
|
||||
logger.info('Token aggregation indexer disabled by ENABLE_INDEXER flag');
|
||||
}
|
||||
|
||||
this.omnlPoller?.start();
|
||||
|
||||
// Start server
|
||||
this.app.listen(this.port, () => {
|
||||
logger.info(`Token Aggregation Service listening on port ${this.port}`);
|
||||
@@ -196,6 +228,7 @@ export class ApiServer {
|
||||
}
|
||||
|
||||
async stop(): Promise<void> {
|
||||
this.omnlPoller?.stop();
|
||||
this.indexer?.stopAll();
|
||||
logger.info('Server stopped');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user