mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Re-use the response from forceSSL.
This commit is contained in:
parent
6eaf090bde
commit
9696a5f8f2
@ -1,15 +1,5 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
|
|
||||||
function forceSSL(req) {
|
|
||||||
if (process.env.FORCE_SSL && req.nextUrl.protocol === 'http:') {
|
|
||||||
const response = NextResponse.next();
|
|
||||||
|
|
||||||
response.headers.set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function customScriptName(req) {
|
function customScriptName(req) {
|
||||||
const scriptName = process.env.TRACKER_SCRIPT_NAME;
|
const scriptName = process.env.TRACKER_SCRIPT_NAME;
|
||||||
|
|
||||||
@ -30,8 +20,16 @@ function disableLogin(req) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function forceSSL(req, res) {
|
||||||
|
if (process.env.FORCE_SSL && req.nextUrl.protocol === 'http:') {
|
||||||
|
res.headers.set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
export function middleware(req) {
|
export function middleware(req) {
|
||||||
const fns = [customScriptName, disableLogin, forceSSL];
|
const fns = [customScriptName, disableLogin];
|
||||||
|
|
||||||
for (const fn of fns) {
|
for (const fn of fns) {
|
||||||
const res = fn(req);
|
const res = fn(req);
|
||||||
@ -40,5 +38,5 @@ export function middleware(req) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.next();
|
return forceSSL(req, NextResponse.next());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user