vite - How to set headers for assets within _appimmutableworkers? - Stack Overflow

I've successfully built a SvelteKit app, but when I try to run npm rum preview, I see that the fol

I've successfully built a SvelteKit app, but when I try to run npm rum preview, I see that the following asset was unable to be loaded:

http://localhost:4173/_app/immutable/workers/shout.wasm.worker-fuz9AyH7.js.

The browser console says:

Because your site has the Cross-Origin Embedder Policy (COEP) enabled, each embedded iframe must also specify this policy. This behavior protects private data from being exposed to untrusted third party sites.

To solve this, add one of following to the embedded frame’s HTML response header:

Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Embedder-Policy: credentialless (Chrome > 96)

How do I configure the static assets served from "_app/immutable/workers" to have the Cross-Origin-Embedder-Policy: require-corp headers?


Current setup of vite.config.ts

const viteServerConfig = () => ({
    name: "add-headers",
    configureServer: (server) => {
        server.middlewares.use((req, res, next) => {
            res.setHeader("Access-Control-Allow-Origin", "*");
            res.setHeader("Access-Control-Allow-Methods", "GET");
            res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
            res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
            next();
        });
    },
});

export default defineConfig({
    plugins: [
        sveltekit(),
        Icons({
            compiler: "svelte",
        }),
        viteServerConfig(),
    ],
    server: {
        open: "/",
        headers: {
            "Cross-Origin-Embedder-Policy": "require-corp",
            "Cross-Origin-Opener-Policy": "same-origin",
        },
        host: '0.0.0.0',
    },
    worker: {
        format: "es",
    },
    build: {
        outDir: "dist",
        target: "ES2022"
    } 
  },

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745650265a4638220.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信