How to add response headers for cors, coop, coep, etc on all routes?
The site I'm building needs to be cross origin isolated so specifically i need to add coop and coep response headers to all the pages and unfortunately the only section that mentions this in the docs points to a broken link
https://tanstack.com/start/latest/docs/framework/react/middleware#readingmodifying-the-server-response
The link to server function context utilities is dead unfortunately
Middleware | TanStack Start React Docs
What is Server Function Middleware? Middleware allows you to customize the behavior of server functions created with createServerFn with things like shared validation, context, and much more. Middlewa...
12 Replies
inland-turquoise•6mo ago
do you need to add those headers for server functions?
probable-pinkOP•6mo ago
yeah i need them for everything but im fine with manually doing it for server functions
inland-turquoise•6mo ago
what does "everything" mean?
probable-pinkOP•6mo ago
so if i make a request to a page and i want it to be cross origin isolated the page itself should have those headers attached
inland-turquoise•6mo ago
so you need it for the SSR request/response as well?
probable-pinkOP•6mo ago
Yeah I do. I actually am not sure if i need it for apis and server functions on the same domain but it's needed for the SSR request and response
inland-turquoise•6mo ago
right now you cant add that to SSR responses
we'll add a way soon though
probable-pinkOP•6mo ago
is nitro a dev only thing or is it used for the production server too?
inland-turquoise•6mo ago
both
probable-pinkOP•6mo ago
i think there is a way to add headers to nitro route rules from what im seeing
inland-turquoise•6mo ago
that will go away though
as we will use nitro's h3 only in future
not nitro itself
but you'll be able to configure middlewares to manipulate the headers as you need it
out of interest, what are you building that needs these headers?
probable-pinkOP•6mo ago
a web based game that uses shared memory multithreading 😅
it's kind of abusing the web platform but it works
i have it mostly built on nextjs but my problem is that nextjs is really slow to develop on with its compilation step so i wanted to use vite which is much faster
and tanstack start is the best looking react metaframework on vite so....
im going to use the nitro route rules for now and will upgrade when you all have the middleware header modification stuff ready