Staging all basic files.
This commit is contained in:
31
server.js
Normal file
31
server.js
Normal file
@@ -0,0 +1,31 @@
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user