-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (41 loc) · 1.31 KB
/
app.js
File metadata and controls
51 lines (41 loc) · 1.31 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
42
43
44
45
46
47
48
49
50
51
import express from 'express';
import { config } from './src/config/config.js';
import path from 'path';
import connectMongo from './src/models/mongoose.js';
// import mongoSanitize from "express-mongo-sanitize";
// import methodOverride from 'method-override'
// import cookieParser from "cookie-parser";
import adminRouter from './src/routes/admin.js';
import cors from "cors";
import projectsRouter from './src/routes/projects.js';
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Connect to MongoDB
connectMongo();
// some middlewares
app.use(express.json());
app.use(cors( ))
app.use(express.urlencoded({ extended: true }));
// app.use(cookieParser())
// app.use(methodOverride("_method"));
// app.use(mongoSanitize());
app.use(adminRouter);
app.use(projectsRouter);
app.disable('x-powered-by');
app.get('/', (req, res) => {
res.send('Hello World!');
});
// Handle 404 errors
app.use((req, res, next) => {
res.status(404).render("404", { url: req.originalUrl });
});
// Error-handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send("Something went wrong!");
});
const port = 3000;
app.listen(config.server.port, () => {
console.log(`Server is running on http://localhost:${config.server.port}`);
});