Skip to content

Commit

Permalink
docs(api-proxy): update code exmaple with explicit require (#21830)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
hangindev and GatsbyJS Bot committed Mar 2, 2020
1 parent 3ba9f9c commit 097b235
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions docs/docs/api-proxy.md
Expand Up @@ -47,13 +47,16 @@ Keep in mind that `proxy` only has effect in development (with `gatsby develop`)
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.

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

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

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

module.exports = {
developMiddleware: app => {
app.use(
"/.netlify/functions/",
proxy({
createProxyMiddleware({
target: "http://localhost:9000",
secure: false, // Do not reject self-signed certificates.
pathRewrite: {
Expand Down

0 comments on commit 097b235

Please sign in to comment.