-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (29 loc) · 970 Bytes
/
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
const
dontenv = require('dotenv').load(),
express = require('express'),
app = express(),
logger = require('morgan'),
bodyParser = require('body-parser'),
mongoose = require('mongoose'),
httpClient = require('request'),
MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost/move-it',
PORT = process.env.PORT || 3001,
usersRoutes = require('./routes/users.js'),
apiRoutes = require('./routes/apis.js')
mongoose.connect(MONGODB_URI, (err) => {
console.log(err || "Connected to MongoDB.")
})
app.use(express.static(`${__dirname}/client/build`))
app.use(logger('dev'))
app.use(bodyParser.json())
app.get('/api', (req, res) => {
res.json({message:"API root."})
})
app.use('/api/search', apiRoutes)
app.use('/api/users', usersRoutes)
app.use('*', (req, res) => {
res.sendFile(`${__dirname}/client/build/index.html`)
})
app.listen(PORT, (err) => {
console.log(err || `Server running on port ${PORT}.`)
})