File size: 707 Bytes
5dfbe50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { cors as honoCors } from 'hono/cors';
import { config } from '../config';

export const corsMiddleware = honoCors({
  origin: (origin) => {
    // Allow configured origin and localhost in development
    const allowedOrigins = [config.corsOrigin];
    if (config.nodeEnv === 'development') {
      allowedOrigins.push('http://localhost:3000', 'http://localhost:3001', 'http://localhost:3025');
    }
    return allowedOrigins.includes(origin) ? origin : allowedOrigins[0];
  },
  allowHeaders: ['Content-Type', 'Authorization', 'X-Request-ID'],
  allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
  exposeHeaders: ['X-Total-Count', 'X-Request-ID'],
  maxAge: 86400,
  credentials: true,
});