#setting headers for static files in local dev

28 messages · Page 1 of 1 (latest)

silk scaffold
#

how can i do this?

marsh elbowBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

pine quiver
silk scaffold
#

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

pine quiver
#

u can serve your selected files trough a route handler and set the header that way

silk scaffold
#

sounds a bit gross

#

i'll go that route, see how i feel about it

pine quiver
#

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

silk scaffold
#

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

vocal garden
silk scaffold
#

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

silk scaffold
#

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;
}```
silk scaffold
#

Now my local pwa database is working

#

Client side... The future is now