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

Rack middleware initialization happens at different time than rackup #1205

Closed
itamarst opened this issue Nov 17, 2016 · 3 comments
Closed

Rack middleware initialization happens at different time than rackup #1205

itamarst opened this issue Nov 17, 2016 · 3 comments

Comments

@itamarst
Copy link

itamarst commented Nov 17, 2016

Use case: I want to register the server with a service discovery mechanism at startup. The additional functionality involved is well-suited to middleware, and the registration is currently implemented in the middleware's initialize method.

With rackup the middleware is initialized upon server startup.

With Sinatra's use, either at top-level or inside a Sinatra::Base, the middleware is only initialized after the first request is received:

It would be useful if Sinatra had same behavior as rackup, initializing all middleware at server startup.

Sinatra: 1.4.7
Rack: 1.6.4

@itamarst
Copy link
Author

itamarst commented Nov 21, 2016

Example that shows the problem: message is only printed after first request.

example.txt

@zzak
Copy link
Member

zzak commented Dec 14, 2016

This has the added benefit of speeding up the first requests response time 👍

@zzak
Copy link
Member

zzak commented Dec 14, 2016

/cc #1216

@zzak zzak added this to the 2.0.0 milestone Dec 14, 2016
@zzak zzak closed this as completed in cc9f254 Dec 25, 2016
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

2 participants