11import express , { type NextFunction , type Request , type Response } from "express" ;
22import cors from "cors"
33import handleFile from "./routes/handleFile" ;
4- // import expressStatusMonitor from 'express-status-monitor';
54import morgan from "morgan" ;
5+ import { rateLimit } from "express-rate-limit" ;
66
77const app = express ( ) ;
88
@@ -26,6 +26,16 @@ app.use(cors({
2626 optionsSuccessStatus : 200 ,
2727} ) ) ;
2828
29+ const limiter = rateLimit ( {
30+ windowMs : 15 * 60 * 1000 , // 15 minutes
31+ max : isProduction ? 100 : 1000 ,
32+ message : "Too many request from this IP, please try again later" ,
33+ standardHeaders : true ,
34+ legacyHeaders : false
35+ } )
36+
37+ app . use ( limiter ) ;
38+
2939app . use ( express . json ( {
3040 limit : '10mb' , // Prevent large payload attacks
3141 verify : ( req , res , buf ) => {
@@ -42,26 +52,6 @@ app.use(express.urlencoded({ extended: true, limit: '10mb' }));
4252app . use ( morgan ( isProduction ? 'combined' : 'dev' , {
4353 skip : ( req , res ) => req . path === '/health' // Skip health check logs
4454} ) ) ;
45- // if (!isProduction) {
46- // app.use(expressStatusMonitor({
47- // title: 'Candy Share API Status',
48- // path: '/status',
49- // spans: [
50- // { interval: 1, retention: 60 }, // 1 minute intervals, keep 60 datapoints
51- // { interval: 5, retention: 60 },
52- // { interval: 15, retention: 60 }
53- // ],
54- // healthChecks: [
55- // {
56- // protocol: 'http',
57- // host: 'localhost',
58- // path: '/health',
59- // port: PORT.toString()
60- // }
61- // ],
62- // ignoreStartsWith: '/status' // Don't monitor the status page itself
63- // }));
64- // }
6555
6656app . use ( ( req : Request , res : Response , next : NextFunction ) => {
6757 if ( req . path !== '/health' ) {
0 commit comments