Spaces:
Sleeping
Sleeping
| const express = require("express"); | |
| const { bootstrap } = require("./bootstrap.js"); | |
| const { dbConnection } = require("./Database/DbConnection.js"); | |
| const dotenv = require("dotenv"); | |
| const morgan = require("morgan"); | |
| const cors = require("cors"); | |
| const http = require("http"); // Import http module | |
| // Load environment variables | |
| dotenv.config(); | |
| // Initialize Express app | |
| const app = express(); | |
| // Middleware | |
| app.use(cors()); | |
| app.use(express.json()); | |
| app.use(morgan("dev")); | |
| app.use(express.static("uploads")); | |
| // Database connection | |
| dbConnection(); | |
| // Bootstrap routes and other setup | |
| bootstrap(app); | |
| // Health check endpoint | |
| app.get('/health', (req, res) => res.status(200).send('OK')); | |
| // Set the port | |
| const port = process.env.PORT || 7860; // Use 7860 for Hugging Face Spaces | |
| // Create an HTTP server explicitly | |
| const server = http.createServer(app); | |
| // Start the server | |
| server.listen(port, () => { | |
| console.log(`App listening on port ${port}!`); | |
| }); | |
| // Handle server errors | |
| server.on('error', (err) => { | |
| console.error('Server error:', err); | |
| }); |