Proxying some URLs can be useful when you have a separate API backend development server and you want to send API requests on the same domain.
webpack.config.js
module.exports = {
// ...
devServer: {
proxy: {
"/proxy": {
target: "http://localhost:5000",
},
},
},
};
To run this example use the following command:
npx webpack serve --open
- The script start a proxy server on
http://localhost:5000/
and openhttp://localhost:8080/
in your default browser. - You should see the text on the page itself change to read
Success! Now visit /proxy
. - Now visit the
/proxy
route by clicking on the/proxy
text, you should see the text on the page itself change to readresponse from proxy
.