Complete the code to define the hook function correctly.
export const [1] = async ({ event, resolve }) => { return await resolve(event); };
The handle function is the correct hook to implement middleware in SvelteKit.
Complete the code to define a middleware that logs each request method.
export const handle = async ({ event, resolve }) => {
console.log(event.request.[1]);
return await resolve(event);
};url instead of method to log the HTTP verb.body directly without parsing.The method property of the request object gives the HTTP method like GET or POST.
Fix the error in the middleware to correctly modify the response headers.
export const handle = async ({ event, resolve }) => {
const response = await resolve(event);
response.headers.set('[1]', 'no-store');
return response;
};HTTP headers are case-insensitive but should be written in standard format like Cache-Control.
Fill both blanks to create middleware that blocks requests without a token header.
export const handle = async ({ event, resolve }) => {
const token = event.request.headers.get('[1]');
if (!token) {
return new Response('Unauthorized', { status: [2] });
}
return await resolve(event);
};token.The middleware checks the authorization header and returns status 401 if missing.
Fill all three blanks to create middleware that adds a custom header and logs the response status.
export const handle = async ({ event, resolve }) => {
const response = await resolve(event);
response.headers.set('[1]', '[2]');
console.log('Response status:', response.[3]);
return response;
};statusText instead of status to log the status code.The middleware sets a custom header X-Custom-Header with value SvelteKit and logs the numeric status of the response.