@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.
Files changed (2) hide show
  1. package/dist/index.js +12 -8
  2. 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(pathname, req) {
181
- const protocol = req.socket?.encrypted || req.headers["x-forwarded-proto"] === "https" ? "https" : "http";
182
- const host = req.headers.host || "localhost";
183
- const cleanPath = pathname.replace(/^\/\//, "/");
184
- return `${protocol}://${host}${cleanPath}`;
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 redirectPath = nodeResponse.req.url;
189
- if (redirectPath) {
190
- const fullUrl = getFullUrl(redirectPath, nodeResponse.req);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@universal-middleware/express",
3
- "version": "0.4.10",
3
+ "version": "0.4.12",
4
4
  "type": "module",
5
5
  "description": "Express adapter for universal middlewares",
6
6
  "files": [