mirror of
https://codeberg.org/MarkusThielker/next-ory.git
synced 2025-04-19 09:01:18 +00:00
Update middleware to use forwarded and host headers for nodeHost determination.
This commit is contained in:
parent
ad1e1e2f86
commit
439fdfb84b
1 changed files with 11 additions and 3 deletions
|
@ -12,13 +12,21 @@ export async function middleware(request: NextRequest) {
|
||||||
.then((response) => response.data)
|
.then((response) => response.data)
|
||||||
.catch(() => null);
|
.catch(() => null);
|
||||||
|
|
||||||
const nodeHost = request.nextUrl.protocol + '//' + request.nextUrl.host;
|
|
||||||
|
const forwardedHost = request.headers.get('x-forwarded-host');
|
||||||
|
const hostHeader = request.headers.get('host');
|
||||||
|
const nodeHost = forwardedHost
|
||||||
|
? `${request.nextUrl.protocol}//${forwardedHost}`
|
||||||
|
: hostHeader
|
||||||
|
? `${request.nextUrl.protocol}//${hostHeader}`
|
||||||
|
: `${request.nextUrl.protocol}//${request.nextUrl.host}`;
|
||||||
|
|
||||||
|
|
||||||
if (!session && !request.nextUrl.pathname.startsWith('/flow')) {
|
if (!session && !request.nextUrl.pathname.startsWith('/flow')) {
|
||||||
|
|
||||||
console.log('NO SESSION');
|
console.log('NO SESSION');
|
||||||
|
const fullReturnUrl = `${nodeHost}${request.nextUrl.pathname}${request.nextUrl.search}`;
|
||||||
|
|
||||||
const url = nodeHost + '/flow/login?return_to=' + request.nextUrl.toString();
|
const url = nodeHost + '/flow/login?return_to=' + fullReturnUrl;
|
||||||
|
|
||||||
console.log('REDIRECT TO', url);
|
console.log('REDIRECT TO', url);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue