Created
March 7, 2019 21:15
-
-
Save GingerBear/a409377d94eb49d9e50152d9f76efc0c 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