-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (32 loc) · 1 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
require('dotenv').config()
const express = require('express')
const app = require('express')()
const cors = require('cors')
const mongoose = require('mongoose')
const { gamesRouter, newsRouter } = require('./src/routes')
const { setupCronJobs } = require('./src/jobs')
const { PORT, MONGO_URL } = process.env
app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.use(cors())
app.get('/', (_req, res) => {
res.send('Hello World!')
})
app.use('/games', gamesRouter)
app.use('/news', newsRouter)
app.listen(PORT, main)
/**
* Connects to DB, schedules cron jobs.
*/
async function main() {
try {
// https://mongoosejs.com/docs/migrating_to_6.html#strictquery-is-removed-and-replaced-by-strict
mongoose.set('strictQuery', true)
await mongoose.connect(MONGO_URL)
setupCronJobs()
console.log('Successfully connected to DB')
console.log(`Listening on port ${PORT}`)
} catch (error) {
console.error('error connecting to DB ', error)
}
}