-
Notifications
You must be signed in to change notification settings - Fork 21
/
server.js
77 lines (65 loc) · 1.92 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* eslint-disable import/no-extraneous-dependencies */
/**
* WARNING: this is a DEVELOPMENT server; DO NOT USE it in production!
*
* If you need to make SOLR available, you can use:
* http://github.com/adsabs/adsws
* http://github.com/adsabs/solr-service
*
* @type {exports}
*/
const express = require('express');
const path = require('path');
const compression = require('compression');
const proxy = require('http-proxy-middleware');
const app = express();
const targets = {
dev: 'https://devapi.adsabs.harvard.edu',
prod: 'https://api.adsabs.harvard.edu',
qa: 'https://api.adsabs.harvard.edu',
};
// default configuration
let config = {
// root path for web (usually src/ or dist/)
root: '/src',
// api route, this will be proxied
apiPath: '/v1',
// proxy settings
proxy: {
target: targets[process.env.TARGET || 'dev'],
changeOrigin: true,
},
};
if (process.env.SERVER_ENV === 'release') {
config = Object.assign(config, { root: '/dist' });
}
// serve the static assets
app.use(compression());
app.use('/', express.static(path.join(__dirname, config.root)));
app.use('/test', express.static(path.join(__dirname, '/test')));
app.use('/node_modules', express.static(path.join(__dirname, '/node_modules')));
app.use(
'/bower_components',
express.static(path.join(__dirname, '/bower_components'))
);
app.use('/_tmp', express.static(path.join(__dirname, '/_tmp')));
// other custom proxy config:
var customProxyConfig = {
target: 'http://localhost:5000',
changeOrigin: true,
logLevel: 'debug',
pathRewrite: function(path) {
return path.replace('/v1/orcid', '');
},
onProxyReq: function(req) {
console.dir(req);
},
};
app.use('/v1/orcid', proxy(customProxyConfig));
// proxy api calls to the api endpoint
app.use(config.apiPath, proxy(config.proxy));
// start the server
app.listen(8000, () => {
console.log('config: ', JSON.stringify(config));
console.log('Listening on port 8000');
});