Spaces:
Paused
Paused
Download src/app.js from imkrish/yatra-x-booking: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/spaces/imkrish/yatra-x-booking/resolve/main/src/app.js
- Command line
-
hf download hf://spaces/imkrish/yatra-x-booking/src/app.js
-
curl -L -o app.js https://huggingface.co/spaces/imkrish/yatra-x-booking/resolve/main/src/app.js
1.8 kB
| ; | |
| require('dotenv').config(); | |
| const express = require('express'); | |
| const { connectDB } = require('./db'); | |
| const bookingRoutes = require('./routes/booking.routes'); | |
| const authRoutes = require('./routes/auth.routes'); | |
| const productRoutes = require('./routes/product.routes'); | |
| const orderRoutes = require('./routes/order.routes'); | |
| const { applySecurityMiddleware, authLimiter } = require('./middlewares/security'); | |
| const app = express(); | |
| const PORT = 7860; | |
| // Security middleware (Helmet, CORS, Rate Limiting) | |
| applySecurityMiddleware(app); | |
| // Body parser | |
| app.use(express.json({ limit: '10kb' })); | |
| // Health check | |
| app.get('/health', async (req, res) => { | |
| res.json({ | |
| status: 'healthy', | |
| service: 'booking-service', | |
| timestamp: new Date().toISOString() | |
| }); | |
| }); | |
| // Routes with auth rate limiting on provider auth | |
| app.use('/api/v1/auth/login', authLimiter); | |
| app.use('/api/v1/auth/register', authLimiter); | |
| app.use('/api/v1/bookings', bookingRoutes); | |
| app.use('/api/v1/auth', authRoutes); | |
| app.use('/api/v1/products', productRoutes); | |
| app.use('/api/v1/orders', orderRoutes); | |
| // Error Handler | |
| app.use((err, req, res, next) => { | |
| // Enhanced logging for production debugging | |
| console.error('[Error Details]', { | |
| message: err.message, | |
| stack: err.stack, | |
| path: req.path, | |
| method: req.method, | |
| body: req.body, | |
| query: req.query | |
| }); | |
| res.status(err.status || 500).json({ | |
| error: { | |
| message: err.message || 'Internal Server Error', | |
| // Only include stack in dev | |
| stack: process.env.NODE_ENV === 'development' ? err.stack : undefined | |
| } | |
| }); | |
| }); | |
| // Start server | |
| async function start() { | |
| await connectDB(); | |
| app.listen(PORT, () => { | |
| console.log(`🚀 Booking Service running on port ${PORT}`); | |
| }); | |
| } | |
| start(); | |
| module.exports = app; | |