Download server/cacheServerHook.ts from abhijeetsarkargis/MiniSearch: direct link, hf CLI and curl.
- Browser
- Download file 646 Bytes
-
https://huggingface.co/spaces/abhijeetsarkargis/MiniSearch/resolve/main/server/cacheServerHook.ts
- Command line
-
hf download hf://spaces/abhijeetsarkargis/MiniSearch/server/cacheServerHook.ts
-
curl -L -o cacheServerHook.ts https://huggingface.co/spaces/abhijeetsarkargis/MiniSearch/resolve/main/server/cacheServerHook.ts
646 Bytes
| import type { PreviewServer, ViteDevServer } from "vite"; | |
| export function cacheServerHook<T extends ViteDevServer | PreviewServer>( | |
| server: T, | |
| ) { | |
| server.middlewares.use(async (request, response, next) => { | |
| let cacheControlValue = "public, max-age=86400, must-revalidate"; | |
| if (request.url.startsWith("/assets/")) { | |
| cacheControlValue = "public, max-age=31536000, immutable"; | |
| } else if ( | |
| request.url === "/" || | |
| request.url.startsWith("/?") || | |
| request.url.endsWith(".html") | |
| ) { | |
| cacheControlValue = "no-cache"; | |
| } | |
| response.setHeader("Cache-Control", cacheControlValue); | |
| next(); | |
| }); | |
| } | |