Added calculators
This commit is contained in:
31
hdyc-svelte/src/hooks.server.ts
Normal file
31
hdyc-svelte/src/hooks.server.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import path from 'node:path';
|
||||
import type { Handle } from '@sveltejs/kit';
|
||||
|
||||
const MIME_TYPES: Record<string, string> = {
|
||||
'.js': 'application/javascript; charset=utf-8',
|
||||
'.mjs': 'application/javascript; charset=utf-8',
|
||||
'.css': 'text/css; charset=utf-8',
|
||||
'.json': 'application/json; charset=utf-8',
|
||||
'.svg': 'image/svg+xml; charset=utf-8',
|
||||
'.woff2': 'font/woff2',
|
||||
'.woff': 'font/woff',
|
||||
'.ttf': 'font/ttf',
|
||||
'.otf': 'font/otf'
|
||||
};
|
||||
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
const response = await resolve(event);
|
||||
if (event.url.pathname.startsWith('/_app/')) {
|
||||
const existing = response.headers.get('content-type');
|
||||
const hasValidHeader = existing && existing.trim().length > 0;
|
||||
if (!hasValidHeader) {
|
||||
const extension = path.extname(event.url.pathname).toLowerCase();
|
||||
const mime = extension && MIME_TYPES[extension];
|
||||
if (mime) {
|
||||
response.headers.set('content-type', mime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
};
|
||||
Reference in New Issue
Block a user