Files
bodyshop/server.js
2019-12-03 16:05:34 -07:00

31 lines
931 B
JavaScript

const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const path = require('path');
var enforce = require('express-sslify');
if (process.env.NODE_ENV !== 'production') require('dotenv').config();
const app = express();
const port = process.env.PORT || 5000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(enforce.HTTPS({ trustProtoHeader: true }));
app.use(cors());
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('/service-worker.js', (req, res) => {
res.sendFile(path.resolve(__dirname, '..', 'build', 'service-worker.js'));
});
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
}
app.listen(port, error => {
if (error) throw error;
console.log('Server running on port ' + port);
});