vikejs / vike

🔨 Flexible, lean, community-driven, dependable, fast Vite-based frontend framework.
https://vike.dev
MIT License
4.34k stars 348 forks source link

New setting `headersResponse` #1803

Open nitedani opened 2 months ago

nitedani commented 2 months ago

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 commented 2 months ago

Agreed. Although I'd name it headersResponse (because of pageContext.headers and https://github.com/vikejs/vike/issues/1268).

How much of a priority is it?

gnardini commented 1 month ago

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

brillout commented 1 month ago

@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.