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

Configuring chained requests via express middlewares #1091

Closed
1 task done
retrocausal opened this issue Feb 25, 2020 · 6 comments
Closed
1 task done

Configuring chained requests via express middlewares #1091

retrocausal opened this issue Feb 25, 2020 · 6 comments

Comments

@retrocausal
Copy link

retrocausal commented Feb 25, 2020

What would you like to discuss?

I have a project where I am using express to proxy requests to a backend from the browser

I found an issue that might be related, But was not too sure.

the express configuration is pretty straightforward , and looks like so:

router.use(`route`, middleware1, middleware2);

middlewares use got via a wrapper object . This is by design, so every route handler need not import got and configure options

the wrapper does nothing but provide an execute method, that looks like so:

execute (){
   this.options.method = this.method
   this.options.headers = this.request.headers
   this.options.responseType = this.downstreamContentType
  /* attach body only if method is POST / PUT*/
   try {
          const awaited = await got(this.source, this.options);
    }catch(e){}

}

the problem is, once middleware1 finishes and next() is called within the stack, middleware 2
changes the url/source ,method , adds an Authorization token received by middleware1
and creates a new wrapper - then calls wrapper.execute

this call simply times out. or, gives me an ECONNRESET message in the catch block.

  1. I have tried requesting the same resource via postman and curl after adding the same Authorization token, and it works fine.
  2. I have tried making the above two requests as chained fetch calls, from the browser and it still works.

The issue only happens when I use a multiple middleware stack on a route in express with got
Or, even when i dont use chained middlewares, and try to execute two got requests in a single middleware. the second request still fails.

I am using got v10+
I have not configured a timeout or a retry in got's options, almost everything apart from whats needed is left to its default value
...

Checklist

  • I have read the documentation.
@szmarczak
Copy link
Collaborator

Could you set up a RunKit example? Or create an example repository? I can't recreate the issue by myself.

@szmarczak
Copy link
Collaborator

@retrocausal Friendly ping.

@retrocausal
Copy link
Author

@szmarczak Sorry, I havent been able to create an example repository. I meant to reply earlier, and could not do so.

Should I close this and check later once I have an example repo?

@szmarczak
Copy link
Collaborator

Please try 11.0.0-beta.1 out and let me know if it's fixed or not.

@szmarczak
Copy link
Collaborator

Friendly ping.

@szmarczak
Copy link
Collaborator

Closing due to a lack of response.

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