-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (29 loc) · 796 Bytes
/
app.js
File metadata and controls
35 lines (29 loc) · 796 Bytes
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
const express = require("express");
const cors = require("cors");
const path = require("path");
const routes = require("./backend/routes/index.js");
const app = express();
const port = 3000;
// Middleware
app.use(cors());
app.use(express.json());
app.set("view engine", "html");
app.use(express.static(path.join(__dirname, "frontend")));
app.use((req, res, next) => {
console.log(`Received request: ${req.method} ${req.url}`);
next();
});
app.use('/', routes);
// Error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Something broke!');
});
// 404 handler
app.use((req, res) => {
res.status(404).render('404');
});
// Start the server
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});