generated from root-kings/template-express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
97 lines (77 loc) · 2.11 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const express = require('express')
const mongoose = require('mongoose')
const cors = require('cors')
const logger = require('morgan')
// const multer = require('multer')
// const path = require('path')
const http = require('http')
// const socketIO = require('socket.io')
require('dotenv').config()
const PORT = process.env.PORT || 3000
const MONGODB_URI = process.env.MONGODB_URI
// const UPLOADS_DIR = process.env.UPLOADS_DIR
// const PUBLIC_DIR = path.join(__dirname, process.env.PUBLIC_DIR)
let app = express()
const server = http.createServer(app)
// const io = socketIO(server)
// global.io = io
mongoose.connect(MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
})
mongoose.Promise = global.Promise
let db = mongoose.connection
db.on('error', console.error.bind(console, 'MongoDB connection error:'))
if (process.env.NODE_ENV === 'development') {
app.use(logger('dev'))
}
app.use(cors())
app.use(
express.urlencoded({
extended: true,
limit: '50mb'
})
)
app.use(
express.json({
limit: '50mb'
})
)
// app.use(express.static(PUBLIC_DIR));
// const storage = multer.diskStorage({
// destination: function (req, file, cb) {
// cb(null, path.join(__dirname, UPLOADS_DIR))
// },
// filename: function (req, file, cb) {
// cb(
// null,
// file.originalname.replace(/ /g, '_') +
// '-' +
// new Date().valueOf() +
// path.extname(file.originalname)
// )
// }
// })
// const upload = multer({ storage })
// global.upload = upload
// app.set('view engine', 'pug')
// app.set('views', './views')
// io.on('connection', client => {
// console.log('Client connected.')
// client.on('disconnect', () => {
// console.log('Client disconnected.')
// })
// })
app.use('/', require('./routes'))
// app.get("*", function (req, res) {
// res.sendFile(PUBLIC_DIR + "/index.html");
// });
// make required dirs
// const directories = [UPLOADS_DIR]
// require('./utils/mkdirSync')(directories)
server.listen(PORT, err => {
if (err) throw err
console.info('Listening on port ' + PORT + '...')
})