-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
34 lines (26 loc) · 1.2 KB
/
app.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
const express = require('express');
const path = require('path');
const app = express();
const bodyParser = require('body-parser');
const Bundler = require('parcel-bundler');
const { settings } = require('./package.json');
const { PORT } = require('./server/config');
const { testDataBaseSubmission } = require('./server/database');
app.use(bodyParser.urlencoded({ extended: false })); // TODO: check what the extended means
app.use(bodyParser.json());
// entry file
const file = 'client/index.html';
console.log(`Node env is ${process.env.NODE_ENV}`);
const backend = require("./server/routes");
app.use('/routes', backend);
if(process.env.NODE_ENV === 'LOCAL') {
// bundler settings
const bundlerOptions = { outDir: settings.PARCEL_DIST_DIR };
const bundler = new Bundler(file, bundlerOptions);
app.use(bundler.middleware());
} else if (process.env.NODE_ENV === 'PROD') {
}
// routes should be handled by react router
app.use(express.static(path.join(__dirname, settings.PARCEL_DIST_DIR)));
app.get ('/*', (req, res) => res.sendFile(path.resolve(`${settings.PARCEL_DIST_DIR}/index.html`)));
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));