16 lines
606 B
TypeScript
16 lines
606 B
TypeScript
import { handle as authHandle } from './auth.js';
|
|
import { sequence } from '@sveltejs/kit/hooks';
|
|
import type { Handle } from '@sveltejs/kit';
|
|
|
|
// When behind a reverse proxy that terminates SSL, rewrite the request URL
|
|
// to use https so that SvelteKit generates correct absolute URLs and form actions.
|
|
const httpsProxy: Handle = async ({ event, resolve }) => {
|
|
const proto = event.request.headers.get('x-forwarded-proto');
|
|
if (proto === 'https' && event.url.protocol === 'http:') {
|
|
event.url.protocol = 'https:';
|
|
}
|
|
return resolve(event);
|
|
};
|
|
|
|
export const handle = sequence(httpsProxy, authHandle);
|