-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
35 lines (28 loc) · 1.08 KB
/
server.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
35
const express = require('express');
const proxy = require('http-proxy-middleware');
const path = require('path');
const Server = {
app: function () {
const app = express();
const indexPath = path.join(__dirname, 'index.html')
const publicPath = express.static(path.join(__dirname, 'dist'))
const sparqlProxy = proxy("/sparql-endpoint", {
target: process.env.SPARQL_ENDPOINT || 'https://library-ontodia-org.herokuapp.com/sparql',
pathRewrite: {'/sparql-endpoint' : ''},
changeOrigin: true,
secure: false,
onProxyRes: (proxyRes) => {
proxyRes.headers['Cache-Control'] = 'max-age=600';
delete proxyRes.headers['pragma']
}
});
app.use("/sparql-endpoint", sparqlProxy);
app.use('/assets', publicPath);
app.get('/*', function(_, res) { res.sendFile(indexPath)});
return app;
}
};
const port = (process.env.PORT || 8080);
const app = Server.app();
app.listen(port);
console.log(`Listening at http://localhost:${port}`);