@server/next 0.48.1 → 0.48.3

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 +27 -2
  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) => {
@@ -2477,7 +2498,7 @@ function parseRange(header, size) {
2477
2498
  }
2478
2499
 
2479
2500
  // src/middle/assets.ts
2480
- var CACHE_CONTROL = "public, max-age=3600";
2501
+ var DEFAULT_CACHE = "public, max-age=3600";
2481
2502
  async function assets(ctx) {
2482
2503
  if (!ctx.options.public) return;
2483
2504
  if (ctx.method !== "get" && ctx.method !== "head") return;
@@ -2490,7 +2511,9 @@ async function assets(ctx) {
2490
2511
  if (info ? !meta2 : !await file2.exists()) return;
2491
2512
  const ext = ctx.url.pathname.split(".").pop()?.toLowerCase();
2492
2513
  const ctype = ext && mimes_default[ext] || meta2?.type || ext;
2493
- const headers2 = { "cache-control": CACHE_CONTROL };
2514
+ const headers2 = {
2515
+ "cache-control": resolveCache(ctx.options.cache) ?? DEFAULT_CACHE
2516
+ };
2494
2517
  let tag;
2495
2518
  if (meta2) {
2496
2519
  const stamp = meta2.modified ? meta2.modified.getTime() : 0;
@@ -2906,6 +2929,7 @@ async function createNode(req, app, signal = new AbortController().signal) {
2906
2929
  const path = (req.url || "/").replace(/\/$/, "") || "/";
2907
2930
  const baseUrl = `${scheme}://${host}`;
2908
2931
  const url = new URL(path, baseUrl);
2932
+ forwarded(url, headers2, app.settings.security.trustProxy);
2909
2933
  define(
2910
2934
  url,
2911
2935
  "query",
@@ -2949,6 +2973,7 @@ async function createWinter(req, app, server2) {
2949
2973
  const cookies2 = parseCookies(headers2.cookie);
2950
2974
  const baseUrl = req.url.replace(/\/$/, "") || "/";
2951
2975
  const url = new URL(baseUrl);
2976
+ forwarded(url, headers2, app.settings.security.trustProxy);
2952
2977
  define(
2953
2978
  url,
2954
2979
  "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.3",
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",