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

Expose response object (res) on locals #716

Open
elgreg opened this issue Oct 2, 2024 · 1 comment
Open

Expose response object (res) on locals #716

elgreg opened this issue Oct 2, 2024 · 1 comment

Comments

@elgreg
Copy link
Contributor

elgreg commented Oct 2, 2024

Is your feature request related to a problem? Please describe.

We'd like to be able to add response headers to things as they're rendered. Specifically, we'd like to be able to add a Surrogate-Key header of a page's author, section, tags, etc when we're rendering the article object. Right now, we can't add to the response based on its content because we don't have access to the response object.

Describe the solution you'd like

Assign locals.res to res in amphora somewhere like this: https://github.com/clay/amphora/blob/master/lib/render.js#L119

locals.res = res

Now model renders and other functions that have access to locals can also do something like locals.res.set("Surrogate-Key", author:${data.author.slug})

Of course, when setting it, one would have to check if it already exists, etc, etc., but this ask is more about getting it on the locals object so it's passed around.

@james-owen
Copy link
Member

This sounds good. I wonder if we should expose the response object in only one spot to keep it simple at first. We could pass res to render hooks https://github.com/clay/amphora-html/blob/master/lib/render.js#L148 that can be declared by calling renderer.addPlugins([{render: my-cool-plugin}]) https://github.com/clay/amphora-html/blob/master/lib/setup.js#L149 That plugin will get the full composed page json after it's run through all of the component model files.

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

2 participants