dynamic-proxy-middleware
v1.3.1
Published
a dynamic proxy middleware for webpack-dev-server which can modify proxy config without reboot webpack
Downloads
5
Maintainers
Readme
dynamic-proxy-middleware
Installation
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install dynamic-proxy-middleware
How to use
var dynamicProxyMiddleware = require('dynamic-proxy-middleware')
var server = new WebpackDevServer({
...
before (app, server) {
app.use(dynamicProxyMiddleware({
entry: '/modifyPageEntryUrl',
proxy: {
'/api1': 'http://target1:8080',
'/api2': 'http://target2:9090',
'/api3': 'http://target3:8080',
'/api4': 'http://target4:9090',
},
}))
}
})
server.listen({...})
With a page on localhost:port/modifyPageEntryUrl
, you can modify the proxy as you want
More api
proxy: {
'/api': {
target: 'http://localhost:3000',
pathRewrite: {'^/api' : ''},
secure: false,
changeOrigin: true,
bypass: function(req, res, proxyOptions) {
if (req.headers.accept.indexOf('html') !== -1) {
console.log('Skipping proxy for browser request.');
return '/index.html';
}
}
}
}