From 748d5febde59e6d0d02bf298c85814eb5fe49531 Mon Sep 17 00:00:00 2001 From: Bret Comnes Date: Fri, 27 Apr 2018 14:40:29 -0700 Subject: [PATCH 1/3] Add a note regarding proxying --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index e91c7525..b09eb2fe 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,14 @@ http://localhost:9000/hello -> folder/hello.js (must export a handler(event, con The `build` function will run a single build of the functions in the folder. +### Proxying for local development + +When your function is deployed on Netlify, it will be available at `/.netlify/functions/function-name` for any given deploy context. It is advantageous to proxy the `netlify-lambda serve` development server to the same path on your primary development server. + +Say you are running `webpack-serve` on port 8080 and `netlify-lambda serve` on port 9000. Mounting `localhost:9000` to `/.netlify/functions/` will closely replicate what the final production environment will look like during development, and will allow you to assume the same function url path in development and in production. + +See [netlify/create-react-app-lambda](https://github.com/netlify/create-react-app-lambda/blob/3b5fac5fcbcba0e775b755311d29242f0fc1d68e/package.json#L19) for an example. + ## Webpack Configuration By default the webpack configuration uses `babel-loader` to load all js files. Any `.babelrc` in the directory `netlify-lambda` is run from will be respected. If no `.babelrc` is found, a [few basic settings are used](https://github.com/netlify/netlify-lambda/blob/master/lib/build.js#L11-L15a). From a6734c279f975fc986ed7624b5553cf77a8b4360 Mon Sep 17 00:00:00 2001 From: Bret Comnes Date: Fri, 27 Apr 2018 14:43:12 -0700 Subject: [PATCH 2/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b09eb2fe..1c1f89e9 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ The `build` function will run a single build of the functions in the folder. When your function is deployed on Netlify, it will be available at `/.netlify/functions/function-name` for any given deploy context. It is advantageous to proxy the `netlify-lambda serve` development server to the same path on your primary development server. -Say you are running `webpack-serve` on port 8080 and `netlify-lambda serve` on port 9000. Mounting `localhost:9000` to `/.netlify/functions/` will closely replicate what the final production environment will look like during development, and will allow you to assume the same function url path in development and in production. +Say you are running `webpack-serve` on port 8080 and `netlify-lambda serve` on port 9000. Mounting `localhost:9000` to `/.netlify/functions/` on your `webpack-serve` server (`localhost:8080/.netlify/functions/`) will closely replicate what the final production environment will look like during development, and will allow you to assume the same function url path in development and in production. -See [netlify/create-react-app-lambda](https://github.com/netlify/create-react-app-lambda/blob/3b5fac5fcbcba0e775b755311d29242f0fc1d68e/package.json#L19) for an example. +See [netlify/create-react-app-lambda](https://github.com/netlify/create-react-app-lambda/blob/3b5fac5fcbcba0e775b755311d29242f0fc1d68e/package.json#L19) for an example of how to do this. ## Webpack Configuration From cedb57f2833ac83abcf5960f8c7ee96298559e07 Mon Sep 17 00:00:00 2001 From: Bret Comnes Date: Fri, 27 Apr 2018 14:47:40 -0700 Subject: [PATCH 3/3] Update README.md --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 1c1f89e9..8f041351 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,22 @@ Say you are running `webpack-serve` on port 8080 and `netlify-lambda serve` on p See [netlify/create-react-app-lambda](https://github.com/netlify/create-react-app-lambda/blob/3b5fac5fcbcba0e775b755311d29242f0fc1d68e/package.json#L19) for an example of how to do this. +[Example webpack config](https://github.com/imorente/netlify-functions-example/blob/master/webpack.development.config): + +```js +module.exports = { + mode: 'development', + devServer: { + proxy: { + "/.netlify": { + target: "http://localhost:9000", + pathRewrite: {"^/.netlify/functions" : ""} + } + } + } +} +``` + ## Webpack Configuration By default the webpack configuration uses `babel-loader` to load all js files. Any `.babelrc` in the directory `netlify-lambda` is run from will be respected. If no `.babelrc` is found, a [few basic settings are used](https://github.com/netlify/netlify-lambda/blob/master/lib/build.js#L11-L15a).