Fix issue with force SSL redirects.

This commit is contained in:
Mike Cao 2022-03-15 08:49:42 -07:00
parent 128f15092e
commit 3717b0e888

View File

@ -1,12 +1,13 @@
import { NextResponse } from 'next/server';
function redirectHTTPS(req) {
const host = req.headers.get('host');
if (
process.env.FORCE_SSL &&
!req.headers.get('host').includes('localhost') &&
req.nextUrl.protocol !== 'https'
process.env.NODE_ENV === 'production' &&
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);
}
}