Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package.json proxy configuration expected to work? #380

Closed
mbbender opened this issue Feb 14, 2018 · 5 comments
Closed

Package.json proxy configuration expected to work? #380

mbbender opened this issue Feb 14, 2018 · 5 comments

Comments

@mbbender
Copy link

I'm trying to use the proxy setting to redirect fetch and axios calls locally to a dev server with my API calls but it doesn't seem to be taking in my react-static project. Would a call to fetch not in the static.config.js file be expected to accept this proxy setting? Proxying is working with a basic create-react-app, just not in my react-static project.

@tannerlinsley
Copy link
Contributor

Could you give me an example of what you're trying to do?

@mbbender
Copy link
Author

In a click handler on a button

fetch('/.netlify/functions/hello')
      .then(response => response.json())
      .then(json => this.setState({loading: false, msg: json.msg}));

package.json

"proxy": {
    "/.netlify/functions": {
      "target": "http://localhost:9000",
      "pathRewrite": {
        "^/\\.netlify/functions": ""
      }
    }
  }

@mbbender
Copy link
Author

Just trying to recreate https://github.com/netlify/create-react-app-lambda in my existing react-static project.

@tannerlinsley
Copy link
Contributor

Try this in your static.config.js:

export default {
  ...
  devServer: {
    proxy: {
    "/.netlify/functions": {
      "target": "http://localhost:9000",
      "pathRewrite": {
        "^/\\.netlify/functions": ""
      }
    }
  }
  },
}

@mbbender
Copy link
Author

Success! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants