File size: 1,062 Bytes
f305dcd
 
 
 
 
 
 
7994378
f305dcd
 
7994378
f305dcd
 
02a1b88
f305dcd
 
 
 
 
02a1b88
f305dcd
 
7994378
f305dcd
 
b63c511
f305dcd
 
49f03cc
f305dcd
 
49f03cc
f305dcd
 
49f03cc
f305dcd
 
 
49f03cc
f305dcd
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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);
});