Spaces:
Sleeping
Sleeping
Mohamed Abu Basith
commited on
Commit
·
f305dcd
1
Parent(s):
49f03cc
changes done
Browse files
server.js
CHANGED
|
@@ -1,42 +1,44 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
//
|
| 10 |
-
|
| 11 |
-
// app.use(cors())
|
| 12 |
|
| 13 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
//
|
| 16 |
-
|
| 17 |
-
// app.use(morgan("dev"));
|
| 18 |
-
// app.use(express.static("uploads"));
|
| 19 |
|
| 20 |
-
//
|
| 21 |
-
|
| 22 |
|
| 23 |
-
//
|
|
|
|
| 24 |
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
res.end('Hello from Node.js server!');
|
| 33 |
-
};
|
| 34 |
-
|
| 35 |
-
const server = http.createServer(requestHandler);
|
| 36 |
-
|
| 37 |
-
server.listen(PORT, (err) => {
|
| 38 |
-
if (err) {
|
| 39 |
-
return console.error('Error starting server:', err);
|
| 40 |
-
}
|
| 41 |
-
console.log(`Server is running on port ${PORT}`);
|
| 42 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require("express");
|
| 2 |
+
const { bootstrap } = require("./bootstrap.js");
|
| 3 |
+
const { dbConnection } = require("./Database/DbConnection.js");
|
| 4 |
+
const dotenv = require("dotenv");
|
| 5 |
+
const morgan = require("morgan");
|
| 6 |
+
const cors = require("cors");
|
| 7 |
+
const http = require("http"); // Import http module
|
| 8 |
|
| 9 |
+
// Load environment variables
|
| 10 |
+
dotenv.config();
|
| 11 |
|
| 12 |
+
// Initialize Express app
|
| 13 |
+
const app = express();
|
|
|
|
| 14 |
|
| 15 |
+
// Middleware
|
| 16 |
+
app.use(cors());
|
| 17 |
+
app.use(express.json());
|
| 18 |
+
app.use(morgan("dev"));
|
| 19 |
+
app.use(express.static("uploads"));
|
| 20 |
|
| 21 |
+
// Database connection
|
| 22 |
+
dbConnection();
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
// Bootstrap routes and other setup
|
| 25 |
+
bootstrap(app);
|
| 26 |
|
| 27 |
+
// Health check endpoint
|
| 28 |
+
app.get('/health', (req, res) => res.status(200).send('OK'));
|
| 29 |
|
| 30 |
+
// Set the port
|
| 31 |
+
const port = process.env.PORT || 7860; // Use 7860 for Hugging Face Spaces
|
| 32 |
|
| 33 |
+
// Create an HTTP server explicitly
|
| 34 |
+
const server = http.createServer(app);
|
| 35 |
|
| 36 |
+
// Start the server
|
| 37 |
+
server.listen(port, () => {
|
| 38 |
+
console.log(`App listening on port ${port}!`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
});
|
| 40 |
+
|
| 41 |
+
// Handle server errors
|
| 42 |
+
server.on('error', (err) => {
|
| 43 |
+
console.error('Server error:', err);
|
| 44 |
+
});
|