@universal-middleware/express 0.4.10 → 0.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +12 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -177,17 +177,21 @@ function overrideWriteHead(nodeResponse, callback) {
|
|
|
177
177
|
}
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
|
-
function getFullUrl(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
180
|
+
function getFullUrl(pathnameOrFull, req) {
|
|
181
|
+
try {
|
|
182
|
+
return new URL(pathnameOrFull).href;
|
|
183
|
+
} catch {
|
|
184
|
+
const protocol = req.socket?.encrypted || req.headers["x-forwarded-proto"] === "https" ? "https" : "http";
|
|
185
|
+
const host = req.headers["x-forwarded-host"] || req.headers.host || "localhost";
|
|
186
|
+
const baseUrl = `${protocol}://${host}`;
|
|
187
|
+
return new URL(pathnameOrFull, baseUrl).href;
|
|
188
|
+
}
|
|
185
189
|
}
|
|
186
190
|
function responseAdapter(nodeResponse, bodyInit) {
|
|
187
191
|
if ([301, 302, 303, 307, 308].includes(nodeResponse.statusCode) && nodeResponse.req) {
|
|
188
|
-
const
|
|
189
|
-
if (
|
|
190
|
-
const fullUrl = getFullUrl(
|
|
192
|
+
const location = nodeResponse.getHeader("location");
|
|
193
|
+
if (location) {
|
|
194
|
+
const fullUrl = getFullUrl(location, nodeResponse.req);
|
|
191
195
|
return Response.redirect(fullUrl, nodeResponse.statusCode);
|
|
192
196
|
}
|
|
193
197
|
}
|