相关文章推荐
非常酷的红茶  ·  关于Copy On Write Array ...·  1 年前    · 
会搭讪的日记本  ·  tensorflow - Your ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

https://www.youtube.com/watch?v=Z0sFlwz0YvU

I'm at 20:09 in this tutorial. I set up my proxy like he did:

  "proxy": {
    "/api":{
      "target": "http://localhost:3001/api"

but got an error:

"When specified, "proxy" in package.json must be a string. Instead, the type of "proxy" was "object". Either remove "proxy" from package.json, or make it a string."

So I made a file client/src/setupProxy.js with this code:

const proxy = require('http-proxy-middleware');
module.exports = function(app) {
    app.use(proxy('/api',
        { target: 'http://localhost:3001' }

Now I am getting a 504 gateway timeout error.

Since I made that tutorial proxy cannot be an object try:

"proxy": "http://localhost:3001/api"
"proxy": "http://localhost:3001"

Your request would have to be:

fetch(`/api/login`,...
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.