-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
28 lines (24 loc) · 812 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
const express = require('express');
const path = require('path');
const mongoose = require('mongoose');
const helmet = require('helmet');
const noteRouter = require('./routes/notes');
const userRouter = require('./routes/users');
const app = express();
mongoose.connect(process.env.MONGODB_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
});
app.use(express.json());
app.use(helmet());
app.use(noteRouter);
app.use(userRouter);
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging') {
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '/client/build/index.html'));
});
}
app.listen(process.env.PORT, () => console.log("starting server"));