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

Get current status #5

Open
georgeh opened this issue Jun 23, 2014 · 5 comments
Open

Get current status #5

georgeh opened this issue Jun 23, 2014 · 5 comments

Comments

@georgeh
Copy link
Contributor

georgeh commented Jun 23, 2014

It would be helpful if there was some way to get the current status of whether the maintenance modules is enabled or disabled. This is especially important when using the endpoint to toggle.

This would allow for more complex request handling in maintenance mode.

@alexbeletsky
Copy link
Member

I could see it as endpoint that returns current status maintenance.

HTTP GET http://youapp.com/maintenance?access_key=[SHARED_SECRET_KEY]

with response,

{
  "maintenance": true 
}

Seems to be easy one, if you fine with that please shoot PR, otherwise I can pack it in nearest future.

@georgeh
Copy link
Contributor Author

georgeh commented Jun 25, 2014

My specific need is for other middlewares to know the status. Since middlewares don't have routes, maintenance can't attach itself as a callback to their requests. I want a proxy middleware to know whether we are in maintenance mode or not so it can decide whether to make certain calls and return sane responses.

While a GET API would work, it would add some overhead of the app calling itself.

@alexbeletsky
Copy link
Member

I see several solutions.

  • module itself could expose method, current() or mode() to understand it's status.
var maintenance = require('maintenance');

// some other middleware 
function foo(req, res, next) {
   var current = maintanance.mode();
   // use it further
}

module.exports = foo;
  • maintenance extends request with flag req.maintenance.
// other middleware
function foo(req, res, next) {
   var current = req.maintenance;
}

Both are fine, I bit more like second one.

I wondering, with the latest changes you introduced that next() is not called if mode turned on.. how other middleware function could be called?

@georgeh
Copy link
Contributor Author

georgeh commented Jun 25, 2014

I think the second one is cleaner too, but either would work for me.

The other middleware works because it's not a callback on a route. maintenance() attaches callbacks to routes, the middleware I'm using (simple-http-proxy) is mounted on a path so it doesn't have a route to with callbacks.

That could pose challenges with the second solution - since this is a non-route request, maintenance wouldn't be called to add the current status to the request object. I'll mess around with my setup to see if I can get maintenance to modify a request on my proxied URLs and if so send a PR.

@alexbeletsky
Copy link
Member

Sounds good. Please go ahead, if you need my help - just let me know :)

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