-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (36 loc) · 1.2 KB
/
index.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
const express = require('express')
const cors = require('cors')
const app = express()
const bodyParser = require('body-parser')
const morgan = require('morgan')
const path = require('path')
const schedule = require('node-schedule')
require('module-alias/register')
const cleanUpToken = require('@tasks/token/clean_up_token.task')
const cleanUpApiKey = require('@tasks/api-key/clean_up_api_key.task')
const ApiRouteV1 = require('@routes/v1/api.route')
require('dotenv').config()
app.use(express.static(path.join(__dirname, 'src', 'public')))
morgan.token('body', (req, res) => {
return JSON.stringify(req.body)
})
app.use(
morgan(
':method :url :status :res[content-length] - :response-time ms :body'
)
)
const corsOptions = {
origin: '*',
exposedHeaders: ['Content-Disposition'],
credentials: true
}
app.use(cors(corsOptions))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use('/api/v1', ApiRouteV1)
schedule.scheduleJob('0 0 * * *', cleanUpToken) // Run every 00:00
schedule.scheduleJob('0 0 * * *', cleanUpApiKey) // Run every 00:00
const port = process.env.APP_PORT || 8080
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`)
})