SumAI-Search / server /crossOriginServerHook.ts
github-actions[bot]
Sync to HuggingFace Spaces
6b3405c
raw
history blame contribute delete
808 Bytes
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();
});
}