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

New setting headersResponse #1803

Open
nitedani opened this issue Aug 13, 2024 · 7 comments
Open

New setting headersResponse #1803

nitedani opened this issue Aug 13, 2024 · 7 comments
Labels
enhancement ✨ New feature or request

Comments

@nitedani
Copy link
Member

nitedani commented Aug 13, 2024

Description

I'd like the ability to set response headers in a hook/config.

This would be useful for, for example https://github.com/magne4000/vite-plugin-vercel, so it could allow users to set cache-control headers in their +config.js file, to leverage Vercels edge cache.

I think headers could be a vike core config, for example:

// +config.js
export default {
	headers: { "Cache-Control" : "s-maxage=15" }
}
@brillout
Copy link
Member

Agreed. Although I'd name it headersResponse (because of pageContext.headers and #1268).

How much of a priority is it?

@brillout brillout changed the title Ability to set response headers in a hook New setting headersResponse Aug 14, 2024
@gnardini
Copy link

(I think) related to this I'd like to be able to set a cookie from a +data.ts file.

@brillout
Copy link
Member

@gnardini Indeed with useConfig() it would be a nice addition.

In the meantime, how about the following?

// +data.js

export default (pageContext) => {
  pageContext.theCookieIWantToadd = '...'
}

Then access it at your renderPage() integration.

@BierDav
Copy link

BierDav commented Nov 21, 2024

I use vike-solid and I want to set response cookies dynamically like in solid start where you can use (getRequestEvent() as RequestEvent & { response: Response })?.response?.headers which allows for modification too. It seams that vike dosen't offer something similar

@brillout
Copy link
Member

@BierDav I agree it'd be nice to make it accessible with useConfig() and/or over pageContext. In the meantime, see the workaround in my previous comment.

@BierDav
Copy link

BierDav commented Nov 21, 2024

What is the timeframe until we can get this feature, the workaround is quite tedious for such a simple task.

@brillout
Copy link
Member

Correct me if I'm wrong but I think if you create a component hook then you get a pretty good DX.

Pointers to Solid Start's docs welcome and I'll compare the DX with what we plan for Vike.

There isn't any ETA, but for sure not before we finish our work on Vike's CLI. (I.e. not before the upcoming 0.5.0 release.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants