Created
March 7, 2019 21:15
-
-
Save GingerBear/0ce9e44de782accb84f4c4b60a97f1bc to your computer and use it in GitHub Desktop.
proxy dev server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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