Skip to content

Instantly share code, notes, and snippets.

@rodrigorm
Created May 8, 2020 02:07
Show Gist options
  • Save rodrigorm/3f14c6fd42fee4edb38b37f1354397a7 to your computer and use it in GitHub Desktop.
Save rodrigorm/3f14c6fd42fee4edb38b37f1354397a7 to your computer and use it in GitHub Desktop.
React Native devServer proxy like webpack
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = {
server: {
enhanceMiddleware: (metroMiddleware, server) => {
// console.log(middleware);
// console.log(server);
const proxyMiddleware = createProxyMiddleware('/api', { target: 'http://localhost:3000' });
return (req, res, next) => {
console.log('middleware', req.url);
return proxyMiddleware(req, res, () => metroMiddleware(req, res, next));
// return middleware(req, res, next);
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment