blob: aeed199d0fdf238453fcd976e0918587a0c9eee0 [file] [log] [blame]
Matteo Scandoloe19fa102017-03-09 15:38:59 -08001const httpProxy = require('http-proxy');
2
Matteo Scandoload8df672017-03-29 22:34:38 -07003const target = process.env.PROXY || '192.168.46.100';
4
Matteo Scandoloe19fa102017-03-09 15:38:59 -08005const apiProxy = httpProxy.createProxyServer({
Matteo Scandoload8df672017-03-29 22:34:38 -07006 target: `http://${target}`
Matteo Scandoloe19fa102017-03-09 15:38:59 -08007});
8
9const staticFilesProxy = httpProxy.createProxyServer({
Matteo Scandoload8df672017-03-29 22:34:38 -070010 target: `http://${target}/spa`
Matteo Scandoloe19fa102017-03-09 15:38:59 -080011});
12
13apiProxy.on('error', (error, req, res) => {
14 res.writeHead(500, {
15 'Content-Type': 'text/plain'
16 });
17 console.error('[Proxy]', error);
18});
19
20staticFilesProxy.on('error', (error, req, res) => {
21 res.writeHead(500, {
22 'Content-Type': 'text/plain'
23 });
24 console.error('[Proxy]', error);
25});
26
27module.exports = {
28 api: apiProxy,
29 static: staticFilesProxy
30};