Spaces:
Sleeping
Sleeping
import { PreviewServer, ViteDevServer } from "vite"; | |
export function crossOriginServerHook<T extends ViteDevServer | PreviewServer>( | |
server: T, | |
) { | |
server.middlewares.use((_, response, next) => { | |
/** Server headers for cross origin isolation, which enable clients to use `SharedArrayBuffer` on the Browser. */ | |
const crossOriginIsolationHeaders: { key: string; value: string }[] = [ | |
{ | |
key: "Cross-Origin-Embedder-Policy", | |
value: "require-corp", | |
}, | |
{ | |
key: "Cross-Origin-Opener-Policy", | |
value: "same-origin", | |
}, | |
{ | |
key: "Cross-Origin-Resource-Policy", | |
value: "cross-origin", | |
}, | |
]; | |
crossOriginIsolationHeaders.forEach(({ key, value }) => { | |
response.setHeader(key, value); | |
}); | |
next(); | |
}); | |
} | |