Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remibantos/6c0b6c93bb1a9b1db3e92a38c791a9ba to your computer and use it in GitHub Desktop.
Save remibantos/6c0b6c93bb1a9b1db3e92a38c791a9ba to your computer and use it in GitHub Desktop.
How to stubI backend API calls with webpack dev-server

How to stub backend API calls with webpack-dev-server

Add the following to webpack dev server configuration

devServer: {
  setup: function(app) {
     app.get('/some/path', function(req, res) {
       res.json({ custom: 'response' });
     });
  },
}

Result

When a request is emitted from the JS app to /some/path API URI, you get the custom response instead of HTTP 404 response

Notes:

The 'setup' setting provides access to the Express web framework allowing server routes configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment