JoshCheek / miniature-octo-ironman

It's small. It had 8 legs. It sells weapons of mass comprehension to the most eager learner!
4 stars 4 forks source link

Provide the server's SHA in a header #45

Closed JoshCheek closed 9 years ago

JoshCheek commented 9 years ago

What we want

I'd like to also be able to know what version of our code is currently in production. The version is basically the repo's git SHA.

In the same way we set the sha of the file we're serving, I'd like to serve MOI's SHA. This should be set in a rack middleware. The code will go somewhere in lib/moi, it will be wired into place in config.ru with the use method.

A little bit about Rack

A rack app is ultimately just an object that has a method call, which takes a hash usually named "env", and returns an array of three things, the HTTP status code (this middleware will just forward the app's status code), the response headers (this middleware will add one header into this hash), and some content (this middleware will just forward the app's content).

I don't exactly know how a middleware gets wired in, but remember it's not too sophisticated (maybe it gets instantiated with the app, then when the request comes in, the call method gets invoked, it is left up to the middleware when and how to call the app, and what to do with the app's response).

This page looks pretty decent for understanding how Rack works.

tyrbo commented 9 years ago

Came across this from Google, while just Googling some stuff about Rack. Seems to be right up the alley of what we're looking for.

https://gist.github.com/karmi/423746

JoshCheek commented 9 years ago

Decided to do this one. Looked into the header thing, apparently using 'X-' prefix is deprecated http://stackoverflow.com/questions/3561381/custom-http-headers-naming-conventions

It winds up looking like this

screenshot 2014-10-26 23 33 08