fix: access of undefined in runtime that does have great support of instanceof (#1838)

* fix: access of undefined in open-nextjs hosted runtime

- This change follows the "duck typing" principle which is often more robust than strict instance checking, especially in complex JavaScript environments where objects might come from different contexts or realms.
- Fixes issue where in an opennext hosted runtime, instanceof usage is not sufficent.

* feat: use in operator for better reliabiltiy across runtimes

* fix: linting issue
This commit is contained in:
James Wainwright
2025-03-17 15:03:52 +03:00
committed by GitHub
parent da9953082a
commit 62f3e49ba0
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -249,7 +249,7 @@ export const getSessionCookie = (
config.cookiePrefix = `${config.cookiePrefix}.`;
}
}
const headers = request instanceof Headers ? request : request.headers;
const headers = "headers" in request ? request.headers : request;
const req = request instanceof Request ? request : undefined;
const url = getBaseURL(req?.url, config?.path, req);
const cookies = headers.get("cookie");
@@ -24,7 +24,7 @@ export function getIp(
"forwarded-for",
"forwarded",
];
const headers = req instanceof Request ? req.headers : req;
const headers = "headers" in req ? req.headers : req;
for (const key of keys) {
const value = headers.get(key);
if (typeof value === "string") {