traforo 0.0.6 → 0.0.8
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/dist/cli.js +2 -2
- package/dist/client.js +15 -3
- package/dist/types.d.ts +3 -2
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { goke } from 'goke';
|
|
3
3
|
import { CLI_NAME, runTunnel, parseCommandFromArgv } from './run-tunnel.js';
|
|
4
4
|
const { command, argv } = parseCommandFromArgv(process.argv);
|
|
5
|
-
const cli =
|
|
5
|
+
const cli = goke(CLI_NAME);
|
|
6
6
|
cli
|
|
7
7
|
.command('', 'Expose a local port via tunnel')
|
|
8
8
|
.option('-p, --port <port>', 'Local port to expose (required)')
|
package/dist/client.js
CHANGED
|
@@ -117,11 +117,18 @@ export class TunnelClient {
|
|
|
117
117
|
headers: msg.headers,
|
|
118
118
|
body: msg.method !== 'GET' && msg.method !== 'HEAD' ? body : undefined,
|
|
119
119
|
});
|
|
120
|
-
// Build response headers
|
|
120
|
+
// Build response headers, preserving multi-value Set-Cookie
|
|
121
121
|
const resHeaders = {};
|
|
122
122
|
res.headers.forEach((value, key) => {
|
|
123
|
+
if (key === 'set-cookie') {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
123
126
|
resHeaders[key] = value;
|
|
124
127
|
});
|
|
128
|
+
const cookies = res.headers.getSetCookie();
|
|
129
|
+
if (cookies.length > 0) {
|
|
130
|
+
resHeaders['set-cookie'] = cookies.length === 1 ? cookies[0] : cookies;
|
|
131
|
+
}
|
|
125
132
|
// Check if we should stream the response
|
|
126
133
|
const contentType = res.headers.get('content-type') || '';
|
|
127
134
|
const transferEncoding = res.headers.get('transfer-encoding') || '';
|
|
@@ -194,9 +201,14 @@ export class TunnelClient {
|
|
|
194
201
|
const { localHost, localPort, localHttps } = this.options;
|
|
195
202
|
const protocol = localHttps ? 'wss' : 'ws';
|
|
196
203
|
const url = `${protocol}://${localHost}:${localPort}${msg.path}`;
|
|
197
|
-
|
|
204
|
+
// Forward WebSocket subprotocol if present (e.g. "vite-hmr")
|
|
205
|
+
const subprotocol = msg.headers['sec-websocket-protocol'];
|
|
206
|
+
const protocols = subprotocol
|
|
207
|
+
? subprotocol.split(',').map((p) => p.trim())
|
|
208
|
+
: undefined;
|
|
209
|
+
console.log(`WS OPEN ${msg.path} (${msg.connId})${protocols ? ` protocols=${protocols}` : ''}`);
|
|
198
210
|
try {
|
|
199
|
-
const localWs = new WebSocket(url);
|
|
211
|
+
const localWs = new WebSocket(url, protocols);
|
|
200
212
|
localWs.on('open', () => {
|
|
201
213
|
console.log(`WS CONNECTED ${msg.connId}`);
|
|
202
214
|
this.localWsConnections.set(msg.connId, localWs);
|
package/dist/types.d.ts
CHANGED
|
@@ -25,18 +25,19 @@ export type WsCloseMessage = {
|
|
|
25
25
|
reason: string;
|
|
26
26
|
};
|
|
27
27
|
export type UpstreamMessage = HttpRequestMessage | WsOpenMessage | WsFrameMessage | WsCloseMessage;
|
|
28
|
+
export type ResponseHeaders = Record<string, string | string[]>;
|
|
28
29
|
export type HttpResponseMessage = {
|
|
29
30
|
type: 'http_response';
|
|
30
31
|
id: string;
|
|
31
32
|
status: number;
|
|
32
|
-
headers:
|
|
33
|
+
headers: ResponseHeaders;
|
|
33
34
|
body: string | null;
|
|
34
35
|
};
|
|
35
36
|
export type HttpResponseStartMessage = {
|
|
36
37
|
type: 'http_response_start';
|
|
37
38
|
id: string;
|
|
38
39
|
status: number;
|
|
39
|
-
headers:
|
|
40
|
+
headers: ResponseHeaders;
|
|
40
41
|
};
|
|
41
42
|
export type HttpResponseChunkMessage = {
|
|
42
43
|
type: 'http_response_chunk';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "traforo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "HTTP tunnel via Cloudflare Durable Objects and WebSockets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,11 +34,12 @@
|
|
|
34
34
|
"@types/ws": "^8.18.1",
|
|
35
35
|
"tsx": "^4.20.5",
|
|
36
36
|
"typescript": "^5.7.0",
|
|
37
|
+
"vite": "^7.1.4",
|
|
37
38
|
"vitest": "^3.2.4",
|
|
38
39
|
"wrangler": "^4.24.3"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"
|
|
42
|
+
"goke": "^6.1.2",
|
|
42
43
|
"string-dedent": "^3.0.2",
|
|
43
44
|
"ws": "^8.19.0"
|
|
44
45
|
},
|