-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (35 loc) · 1.14 KB
/
server.js
File metadata and controls
41 lines (35 loc) · 1.14 KB
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
import express from "express";
import cors from "cors";
import APIRoutes from "./src/Routes/index.js";
import bodyParser from "body-parser";
import { join,dirname } from "path";
import {fileURLToPath} from "url";
import dotenv from "dotenv";
dotenv.config();
const PORT = process.env.PORT;
const mainBackend = process.env.MAINBACKEND;
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const indexPath = join(__dirname, "build", "index.html");
//#region middlewares
const app = express();
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors());
app.use(express.static('public'));
// Define API routes
app.use("/api", APIRoutes);
// Error handling middleware for other errors
app.use(function (err, req, res, next) {
// Set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};
// Render the error page
res.status(err.status || 500);
res.json({
error: err.message,
});
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});