JsonRoutes headers with custom content type

Hi all,

I’m trying to set some custom content type headers on some JsonRoutes, like so:

JsonRoutes.setResponseHeaders({
  "Content-Type": "application/fhir+json"
});

I’ve also tried setting in the route itself:

JsonRoutes.add("post", "/fhir/Patient", function (req, res, next) {

  res.setHeader("Access-Control-Allow-Origin", "*");
  res.setHeader("Content-Type", "application/fhir+json");

  // etc etc etc
});

But everything arrives to Postman with a content-type of application/json. Any thoughts on what might be going on? Or how to fix this?

@sashko?

Looks like the current code writes the content type after the custom headers are applied: https://github.com/stubailo/meteor-rest/blob/359532f8ac38e246731c02ee70436ee26d70743b/packages/json-routes/json-routes.js#L110-L134

Hmmmm… would you accept a pull request so we can set custom header types? Or maybe just setHeader() after writeJsonToBody()?

1 Like

Yeah I think we should just change the order of the calls! So you can override that header if you want to. Please send a PR and I’ll try to publish before dinner!

1 Like

Perfect! Just submitted it. If you want it submitted to another branch, just let me know.

Great, going to take a look now.

any update on this? I’m trying to override content-type but is not working