-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
48 lines (37 loc) · 1.21 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
45
46
47
48
require('dotenv').config()
const env = process.env.NODE_ENV
const mongoose = require('mongoose')
const config = require('./config/config')[env]
const express = require('express')
const indexRouter = require('./routes')
const authRouter = require('./routes/auth')
const cubeRouter = require('./routes/cube')
const accessoryRouter = require('./routes/accessory')
const app = express()
let __setOptions = mongoose.Query.prototype.setOptions;
mongoose.Query.prototype.setOptions = function (options) {
__setOptions.apply(this, arguments);
if (this._mongooseOptions.lean == null) this._mongooseOptions.lean = true;
return this;
};
mongoose.connect(config.databaseUrl, {
useNewUrlParser: true,
useUnifiedTopology: true
}, (err) => {
if (err) {
console.error(err)
throw err
}
console.log('Database is setup and running')
})
require('./config/express')(app)
app.use('/', authRouter)
app.use('/', cubeRouter)
app.use('/', accessoryRouter)
app.use('/', indexRouter)
app.get('*', (req, res) => {
res.render('404', {
title: 'Error | Cube Workshop'
})
})
app.listen(config.port, console.log(`Listening on port ${config.port}! Now its up to you...`))