Skip to content

Commit 097b235

Browse files
hangindevGatsbyJS Bot
and
GatsbyJS Bot
authoredMar 2, 2020
docs(api-proxy): update code exmaple with explicit require (#21830)
* docs(api-proxy): update code exmaple with explicit require http-proxy-middleware v1.0.0 introduces breaking change. require/import of http-proxy-middleware is now explicit. * docs(api-proxy): update code exmaples with explicit require with comments that explains how to use the previous version * chore: format Co-authored-by: GatsbyJS Bot <mathews.kyle+gatsbybot@gmail.com>
1 parent 3ba9f9c commit 097b235

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed
 

‎docs/docs/api-proxy.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@ Keep in mind that `proxy` only has effect in development (with `gatsby develop`)
4747
Sometimes you need more granular/flexible access to the development server. Gatsby exposes the [Express.js](https://expressjs.com/) development server to your site's `gatsby-config.js` where you can add Express middleware as needed.
4848

4949
```javascript:title=gatsby-config.js
50-
var proxy = require("http-proxy-middleware")
50+
const { createProxyMiddleware } = require("http-proxy-middleware") //v1.x.x
51+
// Use implicit require for v0.x.x of 'http-proxy-middleware'
52+
// const proxy = require('http-proxy-middleware')
53+
// be sure to replace 'createProxyMiddleware' with 'proxy' where applicable
5154

5255
module.exports = {
5356
developMiddleware: app => {
5457
app.use(
5558
"/.netlify/functions/",
56-
proxy({
59+
createProxyMiddleware({
5760
target: "http://localhost:9000",
5861
pathRewrite: {
5962
"/.netlify/functions/": "",
@@ -71,12 +74,16 @@ Keep in mind that middleware only has effect in development (with `gatsby develo
7174
If you proxy to local APIs with self-signed certificates, set the option `secure` to `false`.
7275

7376
```javascript:title=gatsby-config.js
74-
var proxy = require("http-proxy-middleware")
77+
const { createProxyMiddleware } = require("http-proxy-middleware") //v1.x.x
78+
// Use implicit require for v0.x.x of 'http-proxy-middleware'
79+
// const proxy = require('http-proxy-middleware')
80+
// be sure to replace 'createProxyMiddleware' with 'proxy' where applicable
81+
7582
module.exports = {
7683
developMiddleware: app => {
7784
app.use(
7885
"/.netlify/functions/",
79-
proxy({
86+
createProxyMiddleware({
8087
target: "http://localhost:9000",
8188
secure: false, // Do not reject self-signed certificates.
8289
pathRewrite: {

0 commit comments

Comments
 (0)
Please sign in to comment.