ReactJS: Setting up a Proxy to Lambda functions

yarn add netlify-lambda http-proxy-middleware

src/setupProxy.js

const proxy = require('http-proxy-middleware');

module.exports = function(app)
{
    app.use(proxy('/.netlify/functions/', {
        target: 'http://localhost:9000/',
        'pathRewrite': {
            '^/\\.netlify/functions': '',
        },
    }));
};

/weback.config.js

module.exports = {
	mode: "development",
	devServer: {
		proxy: {
			"/.netlify": {
				target: "http://localhost:9000",
				pathRewrite: {"^/.netlify/functions": ""}
			}
		}
	}
};

package.json

  "scripts": {
    "start:server": "NODE_TLS_REJECT_UNAUTHORIZED=0 netlify-lambda serve --config ./webpack.config.js src/functions"
}

 

 

Gareth
Buy Me A Coffee
back arrowBack to Index