Skip to content
Snippets Groups Projects
Commit fbde8009 authored by esikkala's avatar esikkala
Browse files

Fix static file serving

parent 56301864
No related branches found
No related tags found
No related merge requests found
......@@ -8221,12 +8221,14 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
......@@ -8241,17 +8243,20 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"core-util-is": {
"version": "1.0.2",
......@@ -8368,7 +8373,8 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"ini": {
"version": "1.3.5",
......@@ -8380,6 +8386,7 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
......@@ -8394,6 +8401,7 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
......@@ -8401,12 +8409,14 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"minipass": {
"version": "2.2.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
......@@ -8425,6 +8435,7 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
......@@ -8505,7 +8516,8 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"object-assign": {
"version": "4.1.1",
......@@ -8517,6 +8529,7 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
......@@ -8638,6 +8651,7 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
......
......@@ -5,8 +5,6 @@ import { getPaginatedResults, getAllResults, getByURI } from './sparql/FacetResu
import { getFacet } from './sparql/FacetValues';
const DEFAULT_PORT = 3001;
const app = express();
const apiPath = '/api';
app.set('port', process.env.PORT || DEFAULT_PORT);
app.use(bodyParser.json());
......@@ -17,6 +15,13 @@ app.use(function(req, res, next) {
next();
});
// The root directory from which to serve static assets (React app)
const publicPath = path.join(__dirname, './../public/');
app.use(express.static(publicPath));
// React app makes requests to these api urls
const apiPath = '/api';
// https://medium.com/@Abazhenov/using-async-await-in-express-with-node-8-b8af872c0016
app.get(`${apiPath}/:resultClass/paginated`, async (req, res, next) => {
try {
......@@ -88,9 +93,8 @@ app.get(`${apiPath}/:facetClass/facet/:id`, async (req, res, next) => {
/* Routes are matched to a url in order of their definition
Redirect all the the rest for react-router to handle */
app.get('*', (req, res, next) => {
res.sendFile(path.resolve(__dirname, './../public/', 'index.html'))
.catch(next);
app.get('*', function(request, response) {
response.sendFile(path.join(publicPath, 'index.html'));
});
app.listen(app.get('port'), () => console.log('MMM API listening on port ' + app.get('port')));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment