You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+89-2
Original file line number
Diff line number
Diff line change
@@ -137,7 +137,7 @@ Say you are running `webpack-serve` on port 8080 and `netlify-lambda serve` on p
137
137
138
138
- If you are using with `create-react-app`, see [netlify/create-react-app-lambda](https://github.com/netlify/create-react-app-lambda/blob/f0e94f1d5a42992a2b894bfeae5b8c039a177dd9/src/setupProxy.js) for an example of how to do this with `create-react-app`. [setupProxy is partially documented in the CRA docs](https://facebook.github.io/create-react-app/docs/proxying-api-requests-in-development#configuring-the-proxy-manually). You can also learn how to do this from scratch in a video: https://www.youtube.com/watch?v=3ldSM98nCHI
139
139
- If you are using Gatsby, see [their Advanced Proxying docs](https://www.gatsbyjs.org/docs/api-proxy/#advanced-proxying). This is implemented in the [JAMstack Hackathon Starter](https://github.com/sw-yx/jamstack-hackathon-starter), and here is an accompanying blogpost: [Turning the Static Dynamic: Gatsby + Netlify Functions + Netlify Identity](https://www.gatsbyjs.org/blog/2018-12-17-turning-the-static-dynamic/).
140
-
- If you are using Next.js, see [this issue for how to proxy](https://github.com/netlify/netlify-lambda/pull/28#issuecomment-439675503).
140
+
- If you are using Nuxt.js, see [this issue for how to proxy](https://github.com/netlify/netlify-lambda/pull/28#issuecomment-439675503).
141
141
- If you are using Vue CLI, you may just use https://github.com/netlify/vue-cli-plugin-netlify-lambda/.
142
142
- If you are using with Angular CLI, see the instructions below.
143
143
@@ -159,7 +159,7 @@ module.exports = {
159
159
160
160
<details>
161
161
<summary>
162
-
<b>Using with `Angular CLI`</b>
162
+
<b>Using with <code>Angular CLI</code></b>
163
163
</summary>
164
164
165
165
CORS issues when trying to use netlify-lambdas locally with angular? you need to set up a proxy.
@@ -205,6 +205,93 @@ To make your life easier you can add these to your `scripts` in `package.json`
205
205
206
206
Obviously you need to run up `netlify-lambda` & `angular` at the same time.
207
207
208
+
</details>
209
+
<details>
210
+
<summary>
211
+
<b>Using with <code>Next.js</code></b>
212
+
</summary>
213
+
214
+
Next.js [doesnt use Webpack Dev Server](https://github.com/zeit/next.js/issues/2281), so you can't modify any config in `next.config.js` to get a proxy to run. However, since the CORS proxy issue only happens in dev mode (Functions are on the same domain when deployed on Netlify) you can run Next.js through a Node server for local development:
215
+
216
+
```js
217
+
touch server.js
218
+
yarn add -D http-proxy-middleware express
219
+
```
220
+
221
+
```js
222
+
// server.js
223
+
/* eslint-disable no-console */
224
+
constexpress=require('express');
225
+
constnext=require('next');
226
+
227
+
constdevProxy= {
228
+
'/.netlify': {
229
+
target:'http://localhost:9000',
230
+
pathRewrite: { '^/.netlify/functions':'' }
231
+
}
232
+
};
233
+
234
+
constport=parseInt(process.env.PORT, 10) ||3000;
235
+
constenv=process.env.NODE_ENV;
236
+
constdev= env !=='production';
237
+
constapp=next({
238
+
dir:'.', // base directory where everything is, could move to src later
0 commit comments