-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver-setup.js
More file actions
44 lines (38 loc) · 933 Bytes
/
Copy pathserver-setup.js
File metadata and controls
44 lines (38 loc) · 933 Bytes
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 path = require('path')
const mongoose = require('mongoose')
require('dotenv').config()
//'mongodb://localhost:27017/stravascript'
module.exports = function() {
mongoose
.connect(
process.env.MONGO_URI || 'mongodb://localhost:27017/stravascript',
{
useNewUrlParser: true,
}
)
.then(() => console.log('Connected to MongoDB'))
.catch(err => console.error(err))
const app = express()
app.use(express.json())
app.use(express.static(path.join(__dirname, 'build')))
app.listen(process.env.PORT || 4000, err => {
err ? console.log(err) : console.log('Server ready')
})
app.get(
[
'/',
'/connect',
'/connect/*',
'/goals',
'/code',
'/sport',
'/faq',
'/settings',
],
function(req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'))
}
)
return app
}