-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (33 loc) · 1.04 KB
/
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
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const homeModule = require("./components/home/home.module");
const userModule = require("./components/user/user.module");
const authModule = require("./components/auth/auth.module");
const corsOptions = {
origin: '*',
methods: 'GET, HEAD, PUT, PATCH, POST, DELETE',
credentials: true,
optionsSuccessStatus: 204
};
const app = express()
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public'));
app.use(cors(corsOptions));
app.options('*', cors(corsOptions)); // Enable pre-flight
app.use('/', homeModule.router);
app.use('/auth', authModule.router);
app.use('/users', userModule.router);
const start = () => {
try {
const port = 3000;
app.listen(port, () =>
console.log(`✅ Server is listening on port ${port}.........`)
);
} catch (err) {
console.error('Failed to start server:', err);
}
};
start();
module.exports = app;