res object seems to be missing setHeader()
See original GitHub issueThis looks like an excellent solution for a low bandwidth web serving using functions - eg static pages for a SPA.
however I’m getting an error using your example in the finalhandler module used by express. It appears your mock response object is missing setHeader()
express: 2.5.11 finalhandler: 0.5.0
https://github.com/pillarjs/finalhandler/blob/master/index.js#L202
Perhaps the issues is your code is written for a specific version of express and they’re been breaking changes since?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Error: Can't set headers after they are sent to the client
The res object in Express is a subclass of Node.js's http.ServerResponse (read the http.js source). You are allowed to call res.setHeader(name, value) as ......
Read more >Unable to set header in server.ext() #2307 - hapijs/hapi - GitHub
But I'm looking to have it set conditionally in the .ext() function. From the docs it looks like I should be able to...
Read more >apex - API Header authorization for Bright Pattern
It looks like there is an Problem with the opening bracket after the request.setHeader . However, it looks okay to me. Http http...
Read more >Using HttpRequest Object How To Set Header & Body Elements
I presume I should set the header ServiceAuthHeader elements using req.setHeader(). Thanks in advance for your help. April 6, 2011 ...
Read more >API Reference - Express 4.x
A new body object containing the parsed data is populated on the request object ... res.set() after res.append() will reset the previously-set header...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ejferg
Thanks for the fix. I spent quite a bit of time with the Express code and didn’t spot
x-powered-by
could be disabled. The reason that header is send is not so explicit in the code and I’m not an express user.I think I used express 2.x as your example had and I wasn’t sure if newer version might have broken you mocking of the HTTP objects. I will certainly try it sometime.
I totally agree it’s a great approach for an API serving JSON payloads. I wanted a solution for that and serving my static objects (index.html etc). Seems in that case I got a bit carried away 😃
I might revisit it sometime. It seemed to me that Functions only support strings for buffers (ie in memory copies) rather than streaming from files. That’s fine for dev but not for production.
Thanks again for getting back to me.
@ejferg @SteveALee Hi thanks for reporting the issue… I’ll have a look quite soon 😉
PS: Feel free to make a PR