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

res object seems to be missing setHeader() #2

Closed
SteveALee opened this issue Jan 9, 2017 · 5 comments
Closed

res object seems to be missing setHeader() #2

SteveALee opened this issue Jan 9, 2017 · 5 comments
Assignees

Comments

@SteveALee
Copy link

SteveALee commented Jan 9, 2017

This 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?

@yvele yvele self-assigned this Jan 17, 2017
@ejferg
Copy link

ejferg commented Jan 31, 2017

Has anybody found a work around?

@SteveALee
Copy link
Author

SteveALee commented Jan 31, 2017

@ejferg To be honest, after quite a bit of time looking at options, including connect rather than express, I decide this was not a good approach for several reasons.

  • Many middleware keep state so do not make any sense in a Function and not in a server main loop.
  • Even for static hosting, compared to other servers content will not be streamed so performance is poor
  • Many features a server would manage are handled out side our function by Azure App Service, so this make little sense - eg CORS.

So while using Express and middleware seems like a neat idea in reality I don't think it makes much sense.

Here's a post I did on static serving in Azure

@yvele
Copy link
Owner

yvele commented Jan 31, 2017

@ejferg @SteveALee Hi thanks for reporting the issue.. I'll have a look quite soon ;)

PS: Feel free to make a PR

@yvele
Copy link
Owner

yvele commented Feb 1, 2017

@SteveALee Thank you so much for reporting this issue 😄

It's now fixed in v1.2.0

I didn't notice the error because I'm disabling x-powered-by in all my express applications.

@ejferg @SteveALee Please give it a try and let me know.

@SteveALee Unrelated to this issue, but you consider moving from express 2.x to express 4.x as express 2.x is no longer maintained and have security and performance issues (source: http://expressjs.com/2x/)

@SteveALee This package is good (and fast enough) for managing API endpoints with routing. If you need streaming feature, feel free to make a PR.. 😃 I know Azure Function is improving and may support streaming (soon or already?).


PS: Known workaround consisting in disabling x-powered-by in the express application instance via app.disable("x-powered-by");

@yvele yvele closed this as completed Feb 1, 2017
@SteveALee
Copy link
Author

@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.

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

No branches or pull requests

3 participants