setting headers for static files in local dev
Unanswered
Blanc de Hotot posted this in #help-forum
Blanc de HototOP
how can i do this?
27 Replies
@Blanc de Hotot how can i do this?
wdym by that?
Blanc de HototOP
i want to be able to add headers to static files, when devving locally
it doesnt seem that nextjs allows you to set content headers
i'm thinking i try and use caddy and get the instance to set the headers
u can serve your selected files trough a route handler and set the header that way
Blanc de HototOP
sounds a bit gross
i'll go that route, see how i feel about it
can u tell me your usecase
what u trying to achieve
practical example
there may be a different solution i just dont know what u really trying to do
Blanc de HototOP
load sqlite to it has opfs access for a pwa
the problem is, it has to pull in other imports
so simply loading the worker file and returning it is going to be a massive pain in the arse
maybe it'll work, i'll try it
@Blanc de Hotot you can try using the
headers option in next.config.js: https://nextjs.org/docs/app/api-reference/next-config-js/headers@Rafael Almeida <@239163649531445248> you can try using the `headers` option in `next.config.js`: <https://nextjs.org/docs/app/api-reference/next-config-js/headers>
Blanc de HototOP
yeah, i am, but it that doesnt work
i've looked and a lot of posts (albeit old so maybe somethings changed) states that next doesnt add headers to static files
but maybe if it does now, there's something wrong with my headers config
hrm.. it does seem that those headers arent being sent at all
Blanc de HototOP
jesus christ, it seems like that next simply was ignoring my next.config.js file
no idea why
but put it in middle ware... and now i have persistent sqlite store
so for anyone wondering...
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest) {
const response = NextResponse.next()
response.headers.set( 'Cross-Origin-Opener-Policy', 'same-origin');
response.headers.set( 'Cross-Origin-Embedder-Policy', 'require-corp');
return response;
}Blanc de HototOP
Now my local pwa database is working
Client side... The future is now