Stream: implementers
Topic: Apache Help
Grahame Grieve (Aug 06 2016 at 02:30):
I'm looking for some Apache help.
Grahame Grieve (Aug 06 2016 at 02:30):
some background:
Grahame Grieve (Aug 06 2016 at 02:32):
When a request for a canonical or literal URL of a resource is made (e.g. http://hl7.org/fhir/Patient/example or http://hl7.org/fhir/ValueSet/condition-status), the server responds with a redirect to the appropriate page in the spec
Grahame Grieve (Aug 06 2016 at 02:33):
the redirect first looks at the accept: header, and redirects to either json, xml depending on the accept content type, or else to the html page
Grahame Grieve (Aug 06 2016 at 02:35):
in this way, the spec is an example of itself (not conformant itself, but it will be)
Grahame Grieve (Aug 06 2016 at 02:36):
hl7.org is hosted on IIS. So I have an ASP script that does the redirect. All good
Grahame Grieve (Aug 06 2016 at 02:38):
I'd like the same arrangements to apply to implementation guides. And these might be hosted ona variety of servers. But Apache is the most likely.
Grahame Grieve (Aug 06 2016 at 02:39):
how would do redirects like this on Apache? php? else...?
Grahame Grieve (Aug 06 2016 at 02:41):
most help explains how to use htaccess for this, but isn't that wrong for this context? (htaccess is server administrator stuff..?) (and it won't do Accept: header stuff..._
Grahame Grieve (Aug 06 2016 at 02:41):
for reference, the asp script:
Grahame Grieve (Aug 06 2016 at 02:41):
<%@ language="javascript"%> <% var s = String(Request.ServerVariables("HTTP_ACCEPT")); if (s.indexOf("json") > -1) Response.Redirect("http://hl7.org/fhir/<%literal%>.json"); else if (s.indexOf("xml") > -1) Response.Redirect("http://hl7.org/fhir/<%literal%>.xml"); else Response.Redirect("http://hl7.org/fhir/<%logical%>.html"); %> <!DOCTYPE html> <html> <body> You should not be seeing this page. If you do, ASP has failed badly. </body> </html>
Grahame Grieve (Aug 06 2016 at 02:42):
on the server, this will be at e.g. /fhir/Patient/example/index.asp
Grahame Grieve (Aug 06 2016 at 02:43):
with the tokens replaced
Josh Mandel (Aug 06 2016 at 03:11):
Here's an example using nginx with about 10 lines of custom config.
https://github.com/jmandel/fhir-static-content-types
Josh Mandel (Aug 06 2016 at 03:11):
The relevant file is the nginx config default.conf, which demonstrates how to map a variable from the accept header.
Josh Mandel (Aug 06 2016 at 03:12):
The example.sh script just demonstrates that it works, by downloading the spec, running nginx in docker, and using this config to serve the spec as static content.
Josh Mandel (Aug 06 2016 at 03:30):
@Grahame Grieve note that hl7.org isn't exposing FHIR MIME types:
$ curl -s -v http://hl7.org/fhir/patient-example.json 2>&1 | grep -i content-type < Content-Type: application/json
My nginx config shows how to do this.
Grahame Grieve (Aug 06 2016 at 08:14):
I don't have any clue how that example solves my problem. It's not for Apache, right? and I don't see where the name mapping happens?
Grahame Grieve (Aug 06 2016 at 08:15):
as for the hl7.org server - I thought it was serving the correct mime types. I will investigate
Josh Mandel (Aug 06 2016 at 12:22):
Your question was about apache, but you indicated you didn't have an actual need to do this with apache specifically; so I shared a way to do this with nginx (since it's my preferred tool for this kind of thing, and rapidly approaching Apache in usage numbers across the web).
Josh Mandel (Aug 06 2016 at 12:25):
The "name mapping" happens in the config file, if I understand what you're asking. It's the "try_files" rule, which says "if the accept header wants json, look for a static file on disk by appending ".json" to the requested url.
Josh Mandel (Aug 06 2016 at 12:26):
It's pretty succinct/powerful.
Josh Mandel (Aug 06 2016 at 12:29):
(Also, one cool thing about my example is -- well, if you have docker :p -- you can just run it and see how it works.)
Grahame Grieve (Aug 06 2016 at 13:28):
so the name root mightn't match - the redirect has to not only deal with extensions, but deal with renaming
Grahame Grieve (Aug 06 2016 at 13:29):
and, ok, nginx is fine, but still, what you showed was a config file approach, right? so I can't generate that?
Josh Mandel (Aug 06 2016 at 17:11):
I'm not sure I understand the requirements, @Grahame Grieve. Perhaps you could spell out a few examples of what you expect to happen when specific requests are made?
But if you're looking to write a kind of explicit mapping file, and you want to do it with apache and a .htaccess file, then you can see this updated example -- see the apache examples at https://github.com/jmandel/fhir-static-content-types
Last updated: Apr 12 2022 at 19:14 UTC