Skip to content

Instantly share code, notes, and snippets.

@atomize
Created August 24, 2018 20:00
Show Gist options
  • Save atomize/7262f5b65d5449fa53dd75d5f4144866 to your computer and use it in GitHub Desktop.
Save atomize/7262f5b65d5449fa53dd75d5f4144866 to your computer and use it in GitHub Desktop.
Advanced proxy setup for webpack development server
// https://raw.githubusercontent.com/webpack/webpack-dev-server/master/examples/general/proxy-advanced/webpack.config.js
'use strict';
// our setup function adds behind-the-scenes bits to the config that all of our
// examples need
const { setup } = require('../../util');
module.exports = setup({
context: __dirname,
entry: './app.js',
devServer: {
proxy: {
'/api': {
target: 'http://jsonplaceholder.typicode.com/',
changeOrigin: true,
pathRewrite: {
'^/api': ''
},
bypass(req) {
if (req.url === '/api/nope') {
return '/bypass.html';
}
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment