This commit is contained in:
parent
835aa9aea2
commit
cf231feb8e
1 changed files with 21 additions and 0 deletions
21
hooks.server.ts
Normal file
21
hooks.server.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import type { Handle } from '@sveltejs/kit';
|
||||
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
// Correct origin behind Nginx
|
||||
const host = event.request.headers.get('x-forwarded-host') ?? event.request.headers.get('host');
|
||||
const proto = event.request.headers.get('x-forwarded-proto') ?? 'https';
|
||||
const origin = `${proto}://${host}`;
|
||||
|
||||
// Example: force HTTPS (optional, Nginx should already do this)
|
||||
if (proto === 'http') {
|
||||
return new Response(null, {
|
||||
status: 308,
|
||||
headers: {
|
||||
Location: origin + event.url.pathname + event.url.search
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Proceed with default behavior
|
||||
return resolve(event);
|
||||
};
|
Loading…
Add table
Reference in a new issue