toiljs 0.0.130 → 0.0.131

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.0.131] - 2026-10-19
4
+
5
+ - Preserve the browser Host header through the development Vite proxy so application origin-specific response policies, including localhost popup handoffs, receive the public origin instead of the internal loopback address. Retain multiple Set-Cookie headers, manual redirects, binary bodies, and HEAD handling.
6
+
3
7
  ## [v0.0.130] - 2026-10-19
4
8
 
5
9
  - Format browser security deployment instructions with colored headings and actions, aligned hosting guidance, and spaced rule blocks. Preserve complete copyable expressions and header values, generic project rules, and plain output when terminal colors are disabled.
@@ -1,3 +1,4 @@
1
+ import { request as httpRequest } from 'node:http';
1
2
  import { writeResponseHeader } from 'toiljs/backend';
2
3
  import { builtContentSecurityPolicy } from 'toiljs/shared';
3
4
  const SKIP_REQUEST_HEADERS = new Set([
@@ -20,28 +21,48 @@ const SKIP_RESPONSE_HEADERS = new Set([
20
21
  'transfer-encoding',
21
22
  ]);
22
23
  export async function proxyToVite(request, response, target) {
23
- const url = `http://${target.host}:${String(target.port)}${request.url}`;
24
- const headers = new Headers();
24
+ const headers = { 'accept-encoding': 'identity' };
25
25
  for (const [name, value] of Object.entries(request.headers)) {
26
26
  if (!SKIP_REQUEST_HEADERS.has(name.toLowerCase()))
27
- headers.set(name, value);
27
+ headers[name] = value;
28
28
  }
29
29
  const hasBody = request.method !== 'GET' && request.method !== 'HEAD';
30
30
  const body = hasBody ? await request.buffer() : undefined;
31
- const upstream = await fetch(url, {
32
- method: request.method === 'HEAD' ? 'GET' : request.method,
33
- headers,
34
- body: body && body.length > 0 ? new Uint8Array(body) : undefined,
35
- redirect: 'manual',
31
+ const upstream = await new Promise((resolve, reject) => {
32
+ const outgoing = httpRequest({
33
+ hostname: target.host,
34
+ port: target.port,
35
+ path: request.url,
36
+ method: request.method === 'HEAD' ? 'GET' : request.method,
37
+ headers,
38
+ }, (incoming) => {
39
+ const chunks = [];
40
+ incoming.on('data', (chunk) => chunks.push(chunk));
41
+ incoming.on('error', reject);
42
+ incoming.on('aborted', () => reject(new Error('Vite response aborted')));
43
+ incoming.on('end', () => resolve({
44
+ status: incoming.statusCode ?? 502,
45
+ headers: incoming.headers,
46
+ body: Buffer.concat(chunks),
47
+ }));
48
+ });
49
+ outgoing.on('error', reject);
50
+ outgoing.end(body);
36
51
  });
37
52
  response.status(upstream.status);
38
- upstream.headers.forEach((value, name) => {
39
- if (!SKIP_RESPONSE_HEADERS.has(name))
40
- writeResponseHeader(response, name, value);
41
- });
42
- const buf = Buffer.from(await upstream.arrayBuffer());
43
- if (upstream.headers.get('content-type')?.includes('text/html') &&
44
- !upstream.headers.has('content-security-policy')) {
53
+ for (const [name, value] of Object.entries(upstream.headers)) {
54
+ if (value === undefined || SKIP_RESPONSE_HEADERS.has(name))
55
+ continue;
56
+ if (name === 'set-cookie' && Array.isArray(value)) {
57
+ for (const cookie of value)
58
+ writeResponseHeader(response, name, cookie);
59
+ }
60
+ else
61
+ writeResponseHeader(response, name, Array.isArray(value) ? value.join(', ') : value);
62
+ }
63
+ const buf = upstream.body;
64
+ if (upstream.headers['content-type']?.includes('text/html') &&
65
+ !upstream.headers['content-security-policy']) {
45
66
  const policy = builtContentSecurityPolicy(buf.toString('utf8'));
46
67
  if (policy !== null)
47
68
  response.header('content-security-policy', policy, true);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "toiljs",
3
3
  "type": "module",
4
- "version": "0.0.130",
4
+ "version": "0.0.131",
5
5
  "author": "Dacely",
6
6
  "description": "The modern React framework: a file-based React frontend and a ToilScript-compiled WebAssembly backend.",
7
7
  "repository": {