Skip to content

Commit

Permalink
fix protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixTJDietrich committed Aug 12, 2023
1 parent faebd85 commit 22ae709
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion playground/src/helpers/origin_from_req.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import type { NextApiRequest } from "next/types";

export default function getOriginFromRequest(req: NextApiRequest): string {
const host = req.headers.host;
const protocol = req.headers["x-forwarded-proto"];
let protocol: string | undefined;
const forwardedProto = req.headers["x-forwarded-proto"];
if (typeof forwardedProto === 'string') {
protocol = forwardedProto.split(',')[0];
} else if (Array.isArray(forwardedProto)) {
protocol = forwardedProto[0];
} else {
protocol = 'http';
}
return `${protocol}://${host}`;
}

0 comments on commit 22ae709

Please sign in to comment.