-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (35 loc) · 908 Bytes
/
app.js
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
import express from 'express';
import cors from 'cors';
import routes from './routes/index.js';
const PORT = process.env.PORT || 3000;
const app = express();
// Welcome Response
app.get('/', (req, res) => {
res.json({
message:
'Welcome to Typeform Judging Board System API, Created by Mohamed Fadl <Mohamed.Fadl2852@gmail.com>',
statusCode: 200
});
});
app.use(cors());
app.use(express.json());
app.use('/api', routes);
// 404 Page Not Found
app.use((req, res) =>
res.status(404).json({
message: 'Oops! You are lost, Go to home page 🌏',
statusCode: 404
})
);
// 500 Internal Server Error
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({
message: 'Oops! Something went wrong, Try again later',
error: err.message,
statusCode: 500
});
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});