Open callumlocke opened 7 years ago
@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);
}
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.
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.
I want to set a
Cache-Control
header, but it's unclear from the docs how to do this.