diff --git a/src/app.ts b/src/app.ts index b50bd06..dc40d2b 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,3 +1,198 @@ -import express from "express"; +import express, { Express, Request, Response } from 'express'; +import cors from 'cors'; +import helmet from 'helmet'; +import rateLimit from 'express-rate-limit'; +import hpp from 'hpp'; +import { errorHandler } from './middleware/error.middleware.js'; +import { SEP10AuthService } from './services/sep10.service.js'; +import { SEP12KYCService } from './services/sep12.service.js'; +import { SEP24SettlementService } from './services/sep24.service.js'; +import { createAuthRouter } from './routes/auth.routes.js'; +import { createKYCRouter } from './routes/kyc.routes.js'; +import { createSettlementRouter } from './routes/settlement.routes.js'; -export const app = express(); +export function createApp(): Express { + const app = express(); + + // Security Middleware + app.use(helmet()); + app.use(cors()); + + // Rate Limiting (100 requests per 15 minutes per IP) + const limiter = rateLimit({ + windowMs: 15 * 60 * 1000, + max: 100, + message: { error: { code: 'RATE_LIMIT_EXCEEDED', message: 'Too many requests from this IP, please try again later.' } } + }); + app.use('/api/', limiter); + + // Payload Limits & HTTP Parameter Pollution protection + app.use(express.json({ limit: '1mb' })); + app.use(express.urlencoded({ extended: true, limit: '1mb' })); + app.use(hpp()); + + // Instantiate services + const authService = new SEP10AuthService(); + const kycService = new SEP12KYCService(); + const settlementService = new SEP24SettlementService(); + + // Root endpoint (API Splash Page) + app.get('/', (_req: Request, res: Response) => { + res.send(` + + +
+ + +This is the backend settlement engine for the HaloPay Protocol. It acts as the bridge between the offline-first Merchant POS and the Stellar network, handling authentication, KYC ingestion, and automated fiat off-ramping.
+ +