-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
45 lines (36 loc) · 1.15 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
41
42
43
44
45
/* eslint-disable comma-dangle */
/* eslint-disable no-console */
/* eslint-disable no-undef */
const express = require('express');
const morgan = require('morgan');
const path = require('path');
const cors = require('cors');
const mangaRouter = require('./routes/mangas');
const userRouter = require('./routes/users');
const { dbConnection } = require('./config/db');
const { port } = require('./config/constant');
const { options } = require('./config/middleware');
app = express();
async function main() {
await dbConnection();
app.set('view engine', 'ejs');
app.use(express.json());
app.use(express.static(`${__dirname}/public`));
app.use(
morgan(':method :url :status :res[content-length] - :response-time ms')
);
app.use(cors(options));
app.use('/api', mangaRouter);
app.use('/api', userRouter);
app.use(express.static(path.join(__dirname, 'webapp', 'build')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'webapp', 'build', 'index.html'));
});
return app;
}
main().then((server) => {
server.listen(port, process.env.IP, () => {
console.log(`server running on port ${port}`);
});
});
module.exports = app;