spooder 6.2.4 → 6.2.5

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 (3) hide show
  1. package/bun.lock +3 -3
  2. package/package.json +1 -1
  3. package/src/api.ts +9 -2
package/bun.lock CHANGED
@@ -10,11 +10,11 @@
10
10
  },
11
11
  },
12
12
  "packages": {
13
- "@types/bun": ["@types/bun@1.3.6", "", { "dependencies": { "bun-types": "1.3.6" } }, "sha512-uWCv6FO/8LcpREhenN1d1b6fcspAB+cefwD7uti8C8VffIv0Um08TKMn98FynpTiU38+y2dUO55T11NgDt8VAA=="],
13
+ "@types/bun": ["@types/bun@1.3.8", "", { "dependencies": { "bun-types": "1.3.8" } }, "sha512-3LvWJ2q5GerAXYxO2mffLTqOzEu5qnhEAlh48Vnu8WQfnmSwbgagjGZV6BoHKJztENYEDn6QmVd949W4uESRJA=="],
14
14
 
15
- "@types/node": ["@types/node@25.0.8", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-powIePYMmC3ibL0UJ2i2s0WIbq6cg6UyVFQxSCpaPxxzAaziRfimGivjdF943sSGV6RADVbk0Nvlm5P/FB44Zg=="],
15
+ "@types/node": ["@types/node@25.2.0", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-DZ8VwRFUNzuqJ5khrvwMXHmvPe+zGayJhr2CDNiKB1WBE1ST8Djl00D0IC4vvNmHMdj6DlbYRIaFE7WHjlDl5w=="],
16
16
 
17
- "bun-types": ["bun-types@1.3.6", "", { "dependencies": { "@types/node": "*" } }, "sha512-OlFwHcnNV99r//9v5IIOgQ9Uk37gZqrNMCcqEaExdkVq3Avwqok1bJFmvGMCkCE0FqzdY8VMOZpfpR3lwI+CsQ=="],
17
+ "bun-types": ["bun-types@1.3.8", "", { "dependencies": { "@types/node": "*" } }, "sha512-fL99nxdOWvV4LqjmC+8Q9kW3M4QTtTR1eePs94v5ctGqU8OeceWrSUaRw3JYb7tU3FkMIAjkueehrHPPPGKi5Q=="],
18
18
 
19
19
  "undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
20
20
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "spooder",
3
3
  "author": "Kruithne <kruithne@gmail.com>",
4
4
  "type": "module",
5
- "version": "6.2.4",
5
+ "version": "6.2.5",
6
6
  "module": "./src/api.ts",
7
7
  "repository": {
8
8
  "url": "https://github.com/Kruithne/spooder"
package/src/api.ts CHANGED
@@ -1904,10 +1904,17 @@ export function http_serve(port: number, hostname?: string) {
1904
1904
  });
1905
1905
  }
1906
1906
 
1907
+ const wrap_response = (result: ReturnType<typeof handler>) => {
1908
+ if (result !== null && typeof result === 'object' && !(result instanceof Response) && !(result instanceof Blob))
1909
+ return Response.json(result, { headers: { 'Cache-Control': 'no-store, no-cache, must-revalidate', 'Pragma': 'no-cache' } });
1910
+
1911
+ return result;
1912
+ };
1913
+
1907
1914
  try {
1908
1915
  // GET/HEAD requests don't have bodies, skip validation
1909
1916
  if (req.method === 'GET' || req.method === 'HEAD')
1910
- return handler(req, url, null);
1917
+ return wrap_response(await handler(req, url, null));
1911
1918
 
1912
1919
  if (req.headers.get('Content-Type') !== 'application/json')
1913
1920
  return 400; // Bad Request
@@ -1916,7 +1923,7 @@ export function http_serve(port: number, hostname?: string) {
1916
1923
  if (json === null || typeof json !== 'object' || Array.isArray(json))
1917
1924
  return 400; // Bad Request
1918
1925
 
1919
- return handler(req, url, json as JsonObject);
1926
+ return wrap_response(await handler(req, url, json as JsonObject));
1920
1927
  } catch (e) {
1921
1928
  return 400; // Bad Request
1922
1929
  }