-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (40 loc) · 1.04 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
const express = require( 'express' );
const pkg = require( './package' );
const path = require( 'path' );
const proxy = require( 'express-http-proxy' );
const app = express();
app.use(
express.static( path.join( __dirname, 'build' ) )
);
app.get( '/', function ( req, res ) {
res.sendFile(
path.join( __dirname, 'build', 'index.html' )
);
} );
if ( typeof pkg.proxy !== 'undefined' ) {
for ( var proxy_path in pkg.proxy ) {
if ( ! pkg.proxy[ proxy_path ] ) {
continue;
}
const proxy_config = pkg.proxy[ proxy_path ];
let target;
if ( proxy_config[ 'target-prod' ] ) {
target = proxy_config[ 'target-prod' ];
}
else if ( proxy_config[ 'target' ] ) {
target = proxy_config[ 'target' ];
}
if ( ! target ) {
continue;
}
app.use( proxy_path,
proxy( target, {
proxyReqPathResolver: function( req ) {
return proxy_path + require( 'url' ).parse( req.url ).path;
}
} )
);
}
}
const port = process.env.PORT || 3000;
app.listen( port );