-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
42 lines (32 loc) · 1.04 KB
/
server.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
const express = require('express');
const http = require('http');
const cors = require('cors');
require('dotenv').config({ path: __dirname + '/.env' });
const novelsRouter = require('./routes/novels/novels.router');
const usersRouter = require('./routes/users/users.router');
const db = require('./database/db');
const redis = require('./database/redis');
const auth = require('./utils/authMiddelware');
const authRouter = require('./routes/auth/auth.router.js');
const app = express();
app.use(cors());
app.use(express.json());
app.use(authRouter);
app.use('/novels', auth.authentificateToken, novelsRouter);
app.use('/users', auth.authentificateToken, usersRouter);
app.get('/', (req, res) => {
res.status(200).json('hello');
});
async function startServer() {
await db.connect(function (err) {
if (err) throw err;
console.log('Connected!');
});
await redis.connect();
const PORT = process.env.PORT;
const server = http.createServer(app);
server.listen(PORT, () => {
console.log(`lstening on port ${PORT}`);
});
}
startServer();