Skip to content

Commit

Permalink
fix passport adapter to work behind cloudfront (#3132)
Browse files Browse the repository at this point in the history
(patch)
  • Loading branch information
flybayer authored Jan 18, 2022
1 parent a344c1f commit 1e3ae5d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions nextjs/packages/next/stdlib-server/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,14 @@ function getProtocol(req: MiddlewareRequest) {
if (req.connection.encrypted) {
return 'https'
}

if (!req.headers) return 'http'

const forwardedProto =
req.headers &&
((req.headers['forwarded'] as string)?.match(/(?<=proto=).+/g)?.[0] ||
(req.headers['x-forwarded-proto'] as string))
(req.headers['forwarded'] as string)?.match(/(?<=proto=).+/g)?.[0] ||
(req.headers['x-forwarded-proto'] as string) ||
(req.headers['CloudFront-Forwarded-Proto'] as string)

if (forwardedProto) {
return forwardedProto.split(/\s*,\s*/)[0]
}
Expand Down

0 comments on commit 1e3ae5d

Please sign in to comment.