-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver.js
22 lines (18 loc) · 835 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
require('dotenv').config();
require('./server/db-conn');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// gives server access to static files generated by running yarn build in client
app.use(express.static('./client/mern_azure_example/build/'));
// mount routes
app.use('/api/thoughts/', require('./server/routes/thoughts-route'));
// the asterisk is very important!! as it allows client side routing
// with react-router or w/e client side routing package you use
app.get('/*', (req, res) => {
res.sendFile('index.html', { root: __dirname + '/client/mern_azure_example/build/' });
});
const { PORT } = process.env;
app.listen(PORT, () => console.log(`Wizardry happening on port ${PORT}`));