Skip to content

Instantly share code, notes, and snippets.

@samuelstevens9
Created February 11, 2019 21:21
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 samuelstevens9/5872e72ac915dfc1a8ae2fdcef323899 to your computer and use it in GitHub Desktop.
Save samuelstevens9/5872e72ac915dfc1a8ae2fdcef323899 to your computer and use it in GitHub Desktop.
Simple setupProxy.js for CRA
// src/setupProxy.js
const proxy = require('http-proxy-middleware')
const pkg = require('../package.json')
const target = process.env.PROXY || pkg.proxy
// tslint:disable-next-line:no-console
console.log("setupProxy",target);
module.exports = function(app) {
// app.use(proxy({ target }));
app.use(proxy('/api', {
// pathRewrite: { '^/api': '' },
secure: false,
target,
}));
};
// module.exports = app => {
// if(target){
// app.use((req, res, next) =>{
// // tslint:disable-next-line:no-console
// console.log("setupProxy",target);
// req.accepts('text/html') ? next() : proxy({ target })(req, res, next)
// }
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment