Skip to content

Instantly share code, notes, and snippets.

@GingerBear
Created March 7, 2019 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GingerBear/0ce9e44de782accb84f4c4b60a97f1bc to your computer and use it in GitHub Desktop.
Save GingerBear/0ce9e44de782accb84f4c4b60a97f1bc to your computer and use it in GitHub Desktop.
proxy dev server
const express = require('express');
const path = require('path');
const fs = require('fs');
const proxy = require('http-proxy-middleware');
const app = express();
const proxyConfig = require('./proxy-remote.conf.json');
const port = 4200;
const ngBuildPath = path.join(__dirname, 'dist/projectAbc');
const ngBuildIndex = fs
.readFileSync(path.join(ngBuildPath, 'index.html'))
.toString();
Object.keys(proxyConfig).forEach(route => {
app.use(route, proxy(proxyConfig[route]));
});
app.use(express.static(path.join(__dirname, 'dist/projectAbc')));
app.use((req, res) => {
res.send(ngBuildIndex);
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment