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

What's the right way to set custom HTTP headers for my routes? #18

Open
callumlocke opened this issue Sep 18, 2017 · 3 comments
Open

What's the right way to set custom HTTP headers for my routes? #18

callumlocke opened this issue Sep 18, 2017 · 3 comments

Comments

@callumlocke
Copy link

callumlocke commented Sep 18, 2017

I want to set a Cache-Control header, but it's unclear from the docs how to do this.

@austinkelleher
Copy link
Collaborator

@callumlocke You can set a header on your out in a route.js. For example:

const template = require('./index.marko');

exports.handler = (input, out) => {
  out.setHeader('Cache-Control', 'no-cache')
  template.render(input, out);
}

@philidem
Copy link
Collaborator

philidem commented Sep 26, 2017

NOTE: out.setHeader(...) works when out is an HTTP response stream. out.setHeader(...) will throw error when building statically because a file output stream does not have a setHeader(...) method.

One of the goals of marko-starter was to normalize building statically (writing to file system) and building for the web (writing to HTTP response). We might need to make it a little more clear when handler is being invoked for static build versus HTTP response.

@philidem
Copy link
Collaborator

When building statically we might want to create a sidecar file with the headers. For example, index.html.headers could be produced. This would allow the headers to not be lost when writing to filesystem. Anyways, just a proposal right now so maybe we could come up with something better.

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

3 participants