-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (43 loc) · 1.38 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const express = require('express');
const app = express();
const swaggerDocs = require('./src/services/swagger')
const bodyParser = require('body-parser');
const connectDB = require('./src/db/connec');
require('dotenv').config();
const xss = require('xss-clean');
const helmet = require('helmet');
const cors = require('cors');
const cookieParser = require('cookie-parser');
const signup = require('./src/routes/signupRoute');
const refresh = require('./src/routes/refresh');
const logout = require('./src/routes/logout');
const login = require('./src/routes/loginRoute');
const verify = require('./src/middlewares/VerifyJWT');
const urlRoute = require('./src/routes/getUrl');
const PORT = process.env.PORT || 4000;
swaggerDocs(app, PORT);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cors());
app.use(xss());
app.use(helmet());
app.use(cookieParser());
//routes
app.use('/api/v1', signup);
app.use('/api/v1', urlRoute);
app.use('/api/v1/refresh', refresh);
app.use('/api/v1/login', login);
app.use(verify)
app.use('/api/v1/logout', logout);
const start = async () => {
try {
await connectDB(process.env.MONGO_URI)
.then(() => {console.log('DB connected successfully')})
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`)
})
} catch (error) {
console.log(error)
}
}
start();