diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 8838ae6..0000000 --- a/Dockerfile +++ /dev/null @@ -1,46 +0,0 @@ -FROM node:20-slim AS builder - -WORKDIR /app - -# Copy package files -COPY package*.json ./ - -# Install dependencies -RUN npm ci - -# Copy the rest of the source code -COPY . . - -# Build the application -RUN npm run build - -# Production stage -FROM node:20-slim AS runner - -WORKDIR /app - -# Set environment to production -ENV NODE_ENV=production - -# Copy package files and install production dependencies -COPY package*.json ./ -RUN npm ci --production - -# Copy build artifacts from the builder stage -COPY --from=builder /app/dist ./dist - -# Copy schema files for Drizzle -COPY ./shared/schema.ts ./shared/ -COPY ./drizzle.config.ts ./ - -# Set the database URL environment variable (this will be overridden at runtime) -ENV DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres - -# Set session secret (should be overridden at runtime) -ENV SESSION_SECRET=changeme - -# Expose the port the app runs on -EXPOSE 5000 - -# Start the application -CMD ["node", "dist/index.js"] \ No newline at end of file diff --git a/server/index.ts b/server/index.ts index 6b306f4..c62e93a 100644 --- a/server/index.ts +++ b/server/index.ts @@ -19,22 +19,6 @@ app.use(compression()); app.use(express.json()); app.use(express.urlencoded({ extended: false })); -// Apply rate limiting middleware for API routes -const apiLimiter = rateLimit({ - windowMs: 15 * 60 * 1000, // 15 minutes - max: 100, // limit each IP to 100 requests per windowMs - standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers - legacyHeaders: false, // Disable the `X-RateLimit-*` headers - message: { message: 'Too many requests, please try again later.' }, - skip: (req) => { - // Skip rate limiting for authenticated users with admin role - return req.isAuthenticated() && req.user?.role === 'admin'; - } -}); - -// Apply the rate limiter to API routes -app.use('/api/', apiLimiter); - // HTTP request logging (in development mode) if (process.env.NODE_ENV !== 'production') { app.use(morgan('dev', { diff --git a/server/routes.ts b/server/routes.ts index 7fd83bb..7a06886 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -5,6 +5,7 @@ import { setupSwagger } from "./swagger"; import { storage } from "./storage"; import { apiQuerySchema, PERMISSIONS } from "@shared/schema"; import { ZodError } from "zod"; +import rateLimit from "express-rate-limit"; import { requireAuth, requirePermission, @@ -21,6 +22,25 @@ export async function registerRoutes(app: Express): Promise { // Initialize Role Based Access Control system await initializeRBAC(); + + // Apply rate limiting middleware for API routes + const apiLimiter = rateLimit({ + windowMs: 15 * 60 * 1000, // 15 minutes + max: 100, // limit each IP to 100 requests per windowMs + standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers + legacyHeaders: false, // Disable the `X-RateLimit-*` headers + message: { message: 'Too many requests, please try again later.' }, + skip: (req: any) => { + // Skip rate limiting for authenticated users with admin role + if (req.isAuthenticated && typeof req.isAuthenticated === 'function' && req.isAuthenticated()) { + return req.user?.role === 'admin'; + } + return false; + } + }); + + // Apply the rate limiter to API routes + app.use('/api/', apiLimiter); // Error handler for Zod validation errors const handleZodError = (err: ZodError, res: Response) => {