I'm using webpack dev server to build a single page application. There are many routes like /api, /alpha, /bravo ... /zulu, and they all need to be proxied.
I wrote webpack.config.js file to proxy all URLs.
proxy: {
"/api": "http://localhost:3000",
"/alpha": {
target: "http://localhost:8080",
pathRewrite: { "^/alpha": "" }
},
"/bravo": {
target: "http://localhost:8080",
pathRewrite: { "^/bravo": "" }
},
"/charlie": {
target: "http://localhost:8080",
pathRewrite: { "^/charlie": "" }
},
...
"/zulu": {
target: "http://localhost:8080",
pathRewrite: { "^/zulu": "" }
},
}
It works well, but I had to write too many codes. I wonder is there any way to reduce it? I thought webpack supports a regular expression for this problem, but I couldn't get a solution from the official docs :(