-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (31 loc) · 1014 Bytes
/
index.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
43
44
const express = require('express');
require('dotenv').config();
// Config Location
const { SeqConnection } = require('./configs/db');
// Routes Location
const { UserRouter } = require('./routers/UserRouters');
const { OrderRouter } = require('./routers/OrderRouters');
// Middleware Location
const { Authentication } = require('./middlewares/AuthenticationMiddleware');
const app = express();
app.use(express.json());
// Home route
app.get('/', (req, res) => {
res.send('<h1 style="text-align:center;color:blue;">Welcome to the Order Food App Backend</h1>');
});
// User routes
app.use('/auth', UserRouter);
// Authentication middleware
app.use(Authentication);
// Order routes
app.use('/orders', OrderRouter);
const PORT = process.env.PORT || 8080;
app.listen(PORT, async () => {
try {
await SeqConnection.authenticate();
console.log(`Server is listening on PORT: ${PORT}`);
} catch (error) {
console.error('Failed to connect to the database:', error);
process.exit(1);
}
});