-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.ts
60 lines (45 loc) · 1.19 KB
/
server.ts
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
60
import dotenv from 'dotenv'
const dotEnvResult = dotenv.config()
import path from 'path'
import express from 'express'
import middlewares from './middlewares/global'
import {errorHandler} from './middlewares/errorHandler'
import swagger from './middlewares/swagger'
import config from './config'
import initPassport from './services/passport'
import {seed} from './utils/seeder'
import userRouter from './resources/user/user.router'
import authRouter from './resources/auth/auth.router'
import createLogger from './utils/logger'
const logger = createLogger(module)
export const app = express()
/**
* General setup
*/
if (config.isDev && dotEnvResult.error) {
logger.error('Please create .env file at root folder')
}
app.use(middlewares)
app.set('view engine', 'pug')
app.set('views', 'views')
app.use(
'/bootstrap',
express.static(path.resolve(__dirname, '../node_modules/bootstrap/dist')),
)
initPassport()
if (config.seed) {
app.get('/seed', (_, res) => {
seed()
res.send('Database seeded')
})
}
/**
* Routers
*/
app.use('/auth', authRouter)
app.use('/api/users', userRouter)
app.use('/api-docs', swagger)
app.get('/', (req, res) => {
res.redirect('/api-docs')
})
app.use(errorHandler)