-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
37 lines (27 loc) · 846 Bytes
/
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
// this is the main entry point for your full app
// it serves your frontend & provides access to your API
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const api = require('./api/server');
require('./api/db/mongoose')
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use((req, res, next) => {
console.log(req.method + ': ' + req.path);
next();
});
//heroku
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'))
}
else{
app.use('/', express.static(__dirname + '/client/public'))
app.get('/', (req, res) => {
res.sendFile(__dirname + '/client/public/index.html');
});
}
app.use('/api', api);
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`listening at http://localhost:${port}`));