Fix issue with force SSL redirects.

pull/1030/head
Mike Cao 2022-03-15 08:49:42 -07:00
parent 128f15092e
commit 3717b0e888
1 changed files with 4 additions and 3 deletions

View File

@ -1,12 +1,13 @@
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
function redirectHTTPS(req) { function redirectHTTPS(req) {
const host = req.headers.get('host');
if ( if (
process.env.FORCE_SSL && process.env.FORCE_SSL &&
!req.headers.get('host').includes('localhost') && process.env.NODE_ENV === 'production' &&
req.nextUrl.protocol !== 'https' req.nextUrl.protocol === 'http:'
) { ) {
return NextResponse.redirect(`https://${req.headers.get('host')}${req.nextUrl.pathname}`, 301); return NextResponse.redirect(`https://${host}${req.nextUrl.pathname}`, 301);
} }
} }