@server/next 0.48.1 → 0.48.2

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/index.js +23 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2110,6 +2110,27 @@ function applyCors(res, ctx) {
2110
2110
  }
2111
2111
  }
2112
2112
 
2113
+ // src/helpers/forwarded.ts
2114
+ var first2 = (value) => {
2115
+ const one = Array.isArray(value) ? value[0] : value;
2116
+ return one?.split(",")[0].trim() || void 0;
2117
+ };
2118
+ function forwarded(url, headers2, trustProxy) {
2119
+ if (!trustProxy) return;
2120
+ const proto = first2(headers2["x-forwarded-proto"]);
2121
+ if (proto === "http" || proto === "https") url.protocol = `${proto}:`;
2122
+ const host = first2(headers2["x-forwarded-host"]);
2123
+ const port = first2(headers2["x-forwarded-port"]);
2124
+ if (host?.includes(":")) {
2125
+ url.host = host;
2126
+ } else if (host) {
2127
+ url.hostname = host;
2128
+ url.port = port ?? "";
2129
+ } else if (port) {
2130
+ url.port = port;
2131
+ }
2132
+ }
2133
+
2113
2134
  // src/helpers/createWebsocket.ts
2114
2135
  function createWebsocket(sockets, handlers) {
2115
2136
  const run2 = (event, socket, body) => {
@@ -2906,6 +2927,7 @@ async function createNode(req, app, signal = new AbortController().signal) {
2906
2927
  const path = (req.url || "/").replace(/\/$/, "") || "/";
2907
2928
  const baseUrl = `${scheme}://${host}`;
2908
2929
  const url = new URL(path, baseUrl);
2930
+ forwarded(url, headers2, app.settings.security.trustProxy);
2909
2931
  define(
2910
2932
  url,
2911
2933
  "query",
@@ -2949,6 +2971,7 @@ async function createWinter(req, app, server2) {
2949
2971
  const cookies2 = parseCookies(headers2.cookie);
2950
2972
  const baseUrl = req.url.replace(/\/$/, "") || "/";
2951
2973
  const url = new URL(baseUrl);
2974
+ forwarded(url, headers2, app.settings.security.trustProxy);
2952
2975
  define(
2953
2976
  url,
2954
2977
  "query",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.48.1",
3
+ "version": "0.48.2",
4
4
  "description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
5
5
  "homepage": "https://server-js.com/",
6
6
  "repository": "github:franciscop/server-next",