-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (21 loc) · 767 Bytes
/
server.js
File metadata and controls
30 lines (21 loc) · 767 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
const express = require('express');
const bodyParser = require('body-parser');
const shrinkRay = require('shrink-ray-current');
require('dotenv').config();
const api = require('./backend/routes');
const app = express();
app.use(shrinkRay());
app.use(bodyParser.json());
app.use('/api', api);
if ( process.env.NODE_ENV === 'production' ) {
// Express vai entregar os assets de produção
// Como por exemplo: main.js ou o main.css
app.use(express.static('frontend/build'));
// Express vai entregar o index.html, se não reconhecer a rota
const path = require('path')
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'frontend', 'build', 'index.html'))
})
}
const PORT = process.env.PORT;
app.listen(PORT);