Fix issue with force SSL redirects.
parent
128f15092e
commit
3717b0e888
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue