Master Backend Plan v3.0 + Government Portal + Implementation Order
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* LandveX Master Gateway
|
||||
*
|
||||
* Unifies all backend services:
|
||||
* - Intelligence Lab (port 3002)
|
||||
* - Apollo CRM (/api/apollo)
|
||||
* - Stripe billing
|
||||
* - aamos-ledger (port 3250)
|
||||
* - aamos-incidents (port 3303)
|
||||
* - Auth & API keys
|
||||
*/
|
||||
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import helmet from 'helmet';
|
||||
import rateLimit from 'express-rate-limit';
|
||||
import { createProxyMiddleware } from 'http-proxy-middleware';
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3004;
|
||||
|
||||
// Middleware
|
||||
app.use(helmet());
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// Rate limiting
|
||||
const limiter = rateLimit({
|
||||
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||
max: 100, // limit each IP to 100 requests per windowMs
|
||||
});
|
||||
app.use(limiter);
|
||||
|
||||
// Health check
|
||||
app.get('/health', (_req, res) => {
|
||||
res.json({
|
||||
status: 'ok',
|
||||
version: '0.1.0-master',
|
||||
services: {
|
||||
intelligence: 'http://localhost:3002',
|
||||
apollo: '/api/apollo',
|
||||
ledger: 'http://localhost:3250',
|
||||
incidents: 'http://localhost:3303',
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Proxy to Intelligence Lab
|
||||
app.use('/api/v1', createProxyMiddleware({
|
||||
target: 'http://localhost:3002',
|
||||
changeOrigin: true,
|
||||
pathRewrite: { '^/api/v1': '/api/v1' },
|
||||
}));
|
||||
|
||||
// Proxy to Apollo CRM
|
||||
app.use('/api/apollo', createProxyMiddleware({
|
||||
target: 'http://localhost:3001',
|
||||
changeOrigin: true,
|
||||
pathRewrite: { '^/api/apollo': '/api/apollo' },
|
||||
}));
|
||||
|
||||
// Proxy to Ledger
|
||||
app.use('/api/ledger', createProxyMiddleware({
|
||||
target: 'http://localhost:3250',
|
||||
changeOrigin: true,
|
||||
pathRewrite: { '^/api/ledger': '' },
|
||||
}));
|
||||
|
||||
// Proxy to Incidents
|
||||
app.use('/api/incidents', createProxyMiddleware({
|
||||
target: 'http://localhost:3303',
|
||||
changeOrigin: true,
|
||||
pathRewrite: { '^/api/incidents': '' },
|
||||
}));
|
||||
|
||||
// Stripe webhook
|
||||
app.post('/webhooks/stripe', express.raw({ type: 'application/json' }), (req, res) => {
|
||||
// TODO: Implement Stripe webhook handling
|
||||
res.json({ received: true });
|
||||
});
|
||||
|
||||
// Start server
|
||||
app.listen(PORT, () => {
|
||||
console.log(`🚀 LandveX Master Gateway running on port ${PORT}`);
|
||||
console.log(`📡 Proxying to:`);
|
||||
console.log(` - Intelligence Lab: http://localhost:3002`);
|
||||
console.log(` - Apollo CRM: http://localhost:3001`);
|
||||
console.log(` - Ledger: http://localhost:3250`);
|
||||
console.log(` - Incidents: http://localhost:3303`);
|
||||
});
|
||||
|
||||
export default app;
|
||||
Reference in New Issue
Block a user