Spaces:
Sleeping
Sleeping
| const express = require('express'); | |
| const cors = require('cors'); | |
| const env = require('./config/env'); | |
| const apiRoutes = require('./routes'); | |
| const healthRoutes = require('./routes/health.routes'); | |
| const { errorHandler, notFoundHandler } = require('./middleware/errorHandler'); | |
| const app = express(); | |
| const allowAllOrigins = env.frontendOrigins.includes('*'); | |
| function isLocalDevOrigin(origin) { | |
| try { | |
| const parsed = new URL(origin); | |
| const hostname = String(parsed.hostname || '').toLowerCase(); | |
| const protocol = String(parsed.protocol || '').toLowerCase(); | |
| if (!['http:', 'https:'].includes(protocol)) { | |
| return false; | |
| } | |
| return ['localhost', '127.0.0.1', '::1'].includes(hostname); | |
| } catch (_error) { | |
| return false; | |
| } | |
| } | |
| const corsOptions = { | |
| origin: '*', | |
| }; | |
| app.use(cors(corsOptions)); | |
| app.use(express.json({ limit: '8mb' })); | |
| app.get('/', (_req, res) => { | |
| res.json({ | |
| success: true, | |
| message: 'Care People backend is running.', | |
| data: { | |
| apiPrefix: '/api/v1', | |
| health: '/health', | |
| }, | |
| errorCode: null, | |
| }); | |
| }); | |
| app.use('/health', healthRoutes); | |
| app.use('/api/v1/', apiRoutes); | |
| app.use(notFoundHandler); | |
| app.use(errorHandler); | |
| module.exports = app; | |