@kubohiroya/turbowarp-http-server 0.1.0
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/LICENSE +373 -0
- package/README.ja.md +346 -0
- package/README.md +874 -0
- package/dist/auth/digest-file.d.ts +17 -0
- package/dist/auth/digest-file.js +90 -0
- package/dist/auth/digest-file.js.map +1 -0
- package/dist/auth/digest.d.ts +23 -0
- package/dist/auth/digest.js +139 -0
- package/dist/auth/digest.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +156 -0
- package/dist/cli.js.map +1 -0
- package/dist/community.d.ts +81 -0
- package/dist/community.js +689 -0
- package/dist/community.js.map +1 -0
- package/dist/digest-cli.d.ts +1 -0
- package/dist/digest-cli.js +159 -0
- package/dist/digest-cli.js.map +1 -0
- package/dist/extension-manifest.json +441 -0
- package/dist/protocol.d.ts +59 -0
- package/dist/protocol.js +71 -0
- package/dist/protocol.js.map +1 -0
- package/dist/server.d.ts +89 -0
- package/dist/server.js +650 -0
- package/dist/server.js.map +1 -0
- package/dist/turbowarp-http-server.js +1110 -0
- package/docs/deployment-targets.ja.md +274 -0
- package/docs/turbowarp-http-server.architecture.html +15149 -0
- package/docs/turbowarp-http-server.architecture.json +1014 -0
- package/docs/turbowarp-http-server.architecture.visual-check.1440x900.dark.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.1440x900.light.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.2048x1320.dark.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.2048x1320.light.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.html +32 -0
- package/docs/turbowarp-http-server.architecture.visual-check.json +547 -0
- package/examples/01-hello-form/README.ja.md +46 -0
- package/examples/01-hello-form/server.mjs +59 -0
- package/examples/02-visitor-counter/README.ja.md +39 -0
- package/examples/02-visitor-counter/server.mjs +44 -0
- package/examples/03-message-board/README.ja.md +47 -0
- package/examples/03-message-board/server.mjs +72 -0
- package/examples/04-image-upload/README.ja.md +46 -0
- package/examples/04-image-upload/server.mjs +149 -0
- package/examples/05-live-camera/README.ja.md +47 -0
- package/examples/05-live-camera/server.mjs +147 -0
- package/examples/06-scratch-like-community/README.ja.md +82 -0
- package/examples/06-scratch-like-community/server.mjs +17 -0
- package/examples/README.ja.md +20 -0
- package/package.json +75 -0
- package/schemas/extension-manifest.schema.json +49 -0
- package/src/auth/digest-file.ts +115 -0
- package/src/auth/digest.ts +170 -0
- package/src/block-definitions.json +417 -0
- package/src/cli.ts +172 -0
- package/src/community.ts +815 -0
- package/src/config.ts +12 -0
- package/src/digest-cli.ts +178 -0
- package/src/extension-manifest.ts +149 -0
- package/src/extension.ts +713 -0
- package/src/globals.d.ts +30 -0
- package/src/index.ts +8 -0
- package/src/protocol.ts +132 -0
- package/src/server.ts +880 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extensionName": "TurboWarp-HTTP-Server",
|
|
3
|
+
"blocks": [
|
|
4
|
+
{
|
|
5
|
+
"opcode": "setServerUrl",
|
|
6
|
+
"blockType": "COMMAND",
|
|
7
|
+
"text": "set HTTP bridge URL to [URL]",
|
|
8
|
+
"description": "Sets the WebSocket URL used to reach the HTTP bridge server.",
|
|
9
|
+
"arguments": {
|
|
10
|
+
"URL": {"type": "STRING", "defaultValue": "ws://127.0.0.1:8787/ws"}
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"opcode": "connect",
|
|
15
|
+
"blockType": "COMMAND",
|
|
16
|
+
"text": "connect to HTTP bridge",
|
|
17
|
+
"description": "Opens a WebSocket connection to the configured HTTP bridge server.",
|
|
18
|
+
"arguments": {}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"opcode": "disconnect",
|
|
22
|
+
"blockType": "COMMAND",
|
|
23
|
+
"text": "disconnect from HTTP bridge",
|
|
24
|
+
"description": "Closes the current bridge connection.",
|
|
25
|
+
"arguments": {}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"opcode": "isConnected",
|
|
29
|
+
"blockType": "BOOLEAN",
|
|
30
|
+
"text": "HTTP bridge connected?",
|
|
31
|
+
"description": "Reports whether the bridge WebSocket is currently open.",
|
|
32
|
+
"arguments": {}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"opcode": "sendText",
|
|
36
|
+
"blockType": "COMMAND",
|
|
37
|
+
"text": "send [MESSAGE] to HTTP bridge",
|
|
38
|
+
"description": "Sends a text message to the connected HTTP bridge server.",
|
|
39
|
+
"arguments": {
|
|
40
|
+
"MESSAGE": {"type": "STRING", "defaultValue": "{\"type\":\"ping\"}"}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"opcode": "lastMessage",
|
|
45
|
+
"blockType": "REPORTER",
|
|
46
|
+
"text": "last HTTP bridge message",
|
|
47
|
+
"description": "Returns the most recent text message received from the bridge.",
|
|
48
|
+
"arguments": {}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"opcode": "whenHttpRequestReceived",
|
|
52
|
+
"blockType": "HAT",
|
|
53
|
+
"text": "when HTTP request received",
|
|
54
|
+
"description": "Starts a TurboWarp handler thread when the bridge receives an HTTP request.",
|
|
55
|
+
"arguments": {}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"opcode": "useHttpRequest",
|
|
59
|
+
"blockType": "COMMAND",
|
|
60
|
+
"text": "use HTTP request [ID]",
|
|
61
|
+
"description": "Selects a pending request context by request ID.",
|
|
62
|
+
"arguments": {
|
|
63
|
+
"ID": {"type": "STRING", "defaultValue": "req-1"}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"opcode": "currentRequestId",
|
|
68
|
+
"blockType": "REPORTER",
|
|
69
|
+
"text": "current request ID",
|
|
70
|
+
"description": "Returns the current HTTP request ID.",
|
|
71
|
+
"arguments": {}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"opcode": "currentHttpMethod",
|
|
75
|
+
"blockType": "REPORTER",
|
|
76
|
+
"text": "current HTTP method",
|
|
77
|
+
"description": "Returns the current HTTP request method.",
|
|
78
|
+
"arguments": {}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"opcode": "currentRequestPath",
|
|
82
|
+
"blockType": "REPORTER",
|
|
83
|
+
"text": "current request path",
|
|
84
|
+
"description": "Returns the current HTTP request path.",
|
|
85
|
+
"arguments": {}
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"opcode": "currentRequestUrl",
|
|
89
|
+
"blockType": "REPORTER",
|
|
90
|
+
"text": "current request URL",
|
|
91
|
+
"description": "Returns the current HTTP request URL.",
|
|
92
|
+
"arguments": {}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"opcode": "requestHeader",
|
|
96
|
+
"blockType": "REPORTER",
|
|
97
|
+
"text": "request header [NAME]",
|
|
98
|
+
"description": "Returns the first value of a request header using case-insensitive lookup.",
|
|
99
|
+
"arguments": {
|
|
100
|
+
"NAME": {"type": "STRING", "defaultValue": "accept"}
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"opcode": "queryParameter",
|
|
105
|
+
"blockType": "REPORTER",
|
|
106
|
+
"text": "query parameter [NAME]",
|
|
107
|
+
"description": "Returns the first query parameter value.",
|
|
108
|
+
"arguments": {
|
|
109
|
+
"NAME": {"type": "STRING", "defaultValue": "q"}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"opcode": "pathParameter",
|
|
114
|
+
"blockType": "REPORTER",
|
|
115
|
+
"text": "path parameter [NAME]",
|
|
116
|
+
"description": "Returns a route path parameter value.",
|
|
117
|
+
"arguments": {
|
|
118
|
+
"NAME": {"type": "STRING", "defaultValue": "id"}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"opcode": "currentRequestBody",
|
|
123
|
+
"blockType": "REPORTER",
|
|
124
|
+
"text": "current request body",
|
|
125
|
+
"description": "Returns the current textual request body, or an empty string for non-text bodies.",
|
|
126
|
+
"arguments": {}
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"opcode": "currentRequestContentType",
|
|
130
|
+
"blockType": "REPORTER",
|
|
131
|
+
"text": "current request content type",
|
|
132
|
+
"description": "Returns the current request Content-Type header.",
|
|
133
|
+
"arguments": {}
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"opcode": "currentRequestClientAddress",
|
|
137
|
+
"blockType": "REPORTER",
|
|
138
|
+
"text": "current request client address",
|
|
139
|
+
"description": "Returns the current request client address when available.",
|
|
140
|
+
"arguments": {}
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"opcode": "currentAuthType",
|
|
144
|
+
"blockType": "REPORTER",
|
|
145
|
+
"text": "current auth type",
|
|
146
|
+
"description": "Returns the current authentication type, such as digest or oauth.",
|
|
147
|
+
"arguments": {}
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"opcode": "currentAuthenticatedUser",
|
|
151
|
+
"blockType": "REPORTER",
|
|
152
|
+
"text": "current authenticated user",
|
|
153
|
+
"description": "Returns the authenticated username or a stable user-like profile field when available.",
|
|
154
|
+
"arguments": {}
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"opcode": "currentAuthProvider",
|
|
158
|
+
"blockType": "REPORTER",
|
|
159
|
+
"text": "current auth provider",
|
|
160
|
+
"description": "Returns the authentication provider name when available.",
|
|
161
|
+
"arguments": {}
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"opcode": "currentAuthProfileJson",
|
|
165
|
+
"blockType": "REPORTER",
|
|
166
|
+
"text": "current auth profile JSON",
|
|
167
|
+
"description": "Returns the provider profile object as JSON when available.",
|
|
168
|
+
"arguments": {}
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"opcode": "authProfileField",
|
|
172
|
+
"blockType": "REPORTER",
|
|
173
|
+
"text": "auth profile field [NAME]",
|
|
174
|
+
"description": "Returns a top-level or dotted field from the provider profile object.",
|
|
175
|
+
"arguments": {
|
|
176
|
+
"NAME": {"type": "STRING", "defaultValue": "email"}
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"opcode": "currentResponseStatus",
|
|
181
|
+
"blockType": "REPORTER",
|
|
182
|
+
"text": "current response status",
|
|
183
|
+
"description": "Returns the response status currently being built.",
|
|
184
|
+
"arguments": {}
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"opcode": "setHttpStatus",
|
|
188
|
+
"blockType": "COMMAND",
|
|
189
|
+
"text": "set HTTP status [STATUS]",
|
|
190
|
+
"description": "Sets the current response status.",
|
|
191
|
+
"arguments": {
|
|
192
|
+
"STATUS": {"type": "NUMBER", "defaultValue": 200}
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"opcode": "setResponseHeader",
|
|
197
|
+
"blockType": "COMMAND",
|
|
198
|
+
"text": "set response header [NAME] to [VALUE]",
|
|
199
|
+
"description": "Sets a response header for the current request.",
|
|
200
|
+
"arguments": {
|
|
201
|
+
"NAME": {"type": "STRING", "defaultValue": "content-type"},
|
|
202
|
+
"VALUE": {"type": "STRING", "defaultValue": "text/plain; charset=utf-8"}
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"opcode": "removeResponseHeader",
|
|
207
|
+
"blockType": "COMMAND",
|
|
208
|
+
"text": "remove response header [NAME]",
|
|
209
|
+
"description": "Removes a response header for the current request.",
|
|
210
|
+
"arguments": {
|
|
211
|
+
"NAME": {"type": "STRING", "defaultValue": "content-type"}
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"opcode": "responseHeader",
|
|
216
|
+
"blockType": "REPORTER",
|
|
217
|
+
"text": "response header [NAME]",
|
|
218
|
+
"description": "Returns the first configured response header value.",
|
|
219
|
+
"arguments": {
|
|
220
|
+
"NAME": {"type": "STRING", "defaultValue": "content-type"}
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"opcode": "setResponseBody",
|
|
225
|
+
"blockType": "COMMAND",
|
|
226
|
+
"text": "set response body [BODY]",
|
|
227
|
+
"description": "Sets the current response body without completing the response.",
|
|
228
|
+
"arguments": {
|
|
229
|
+
"BODY": {"type": "STRING", "defaultValue": "Hello"}
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"opcode": "sendResponse",
|
|
234
|
+
"blockType": "COMMAND",
|
|
235
|
+
"text": "send response [BODY]",
|
|
236
|
+
"description": "Sets the response body and completes the current request.",
|
|
237
|
+
"arguments": {
|
|
238
|
+
"BODY": {"type": "STRING", "defaultValue": "Hello"}
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"opcode": "respondWithText",
|
|
243
|
+
"blockType": "COMMAND",
|
|
244
|
+
"text": "respond with text [BODY]",
|
|
245
|
+
"description": "Responds with plain text.",
|
|
246
|
+
"arguments": {
|
|
247
|
+
"BODY": {"type": "STRING", "defaultValue": "Hello"}
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
"opcode": "respondWithHtml",
|
|
252
|
+
"blockType": "COMMAND",
|
|
253
|
+
"text": "respond with HTML [BODY]",
|
|
254
|
+
"description": "Responds with HTML.",
|
|
255
|
+
"arguments": {
|
|
256
|
+
"BODY": {"type": "STRING", "defaultValue": "<p>Hello</p>"}
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
"opcode": "respondWithJson",
|
|
261
|
+
"blockType": "COMMAND",
|
|
262
|
+
"text": "respond with JSON [BODY]",
|
|
263
|
+
"description": "Responds with JSON.",
|
|
264
|
+
"arguments": {
|
|
265
|
+
"BODY": {"type": "STRING", "defaultValue": "{\"ok\":true}"}
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
"opcode": "recordHttpLog",
|
|
270
|
+
"blockType": "COMMAND",
|
|
271
|
+
"text": "record HTTP log [ENTRY]",
|
|
272
|
+
"description": "Adds a structured HTTP log entry JSON string to the extension log buffer.",
|
|
273
|
+
"arguments": {
|
|
274
|
+
"ENTRY": {"type": "STRING", "defaultValue": "{\"method\":\"GET\",\"path\":\"/\",\"status\":200}"}
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
"opcode": "clearHttpLogs",
|
|
279
|
+
"blockType": "COMMAND",
|
|
280
|
+
"text": "clear HTTP logs",
|
|
281
|
+
"description": "Clears the extension log buffer.",
|
|
282
|
+
"arguments": {}
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
"opcode": "httpLogViewerHtml",
|
|
286
|
+
"blockType": "REPORTER",
|
|
287
|
+
"text": "HTTP log viewer HTML",
|
|
288
|
+
"description": "Returns a self-contained virtual-scroll HTML log viewer for buffered HTTP logs.",
|
|
289
|
+
"arguments": {}
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
"opcode": "httpLogViewerHtmlFromJson",
|
|
293
|
+
"blockType": "REPORTER",
|
|
294
|
+
"text": "HTTP log viewer HTML from [LOGS]",
|
|
295
|
+
"description": "Returns a self-contained virtual-scroll HTML log viewer from a JSON array of log entries.",
|
|
296
|
+
"arguments": {
|
|
297
|
+
"LOGS": {"type": "STRING", "defaultValue": "[{\"method\":\"GET\",\"path\":\"/\",\"status\":200}]"}
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
"opcode": "newMarkdownDocument",
|
|
302
|
+
"blockType": "REPORTER",
|
|
303
|
+
"text": "new markdown document",
|
|
304
|
+
"description": "Creates an empty Markdown builder handle.",
|
|
305
|
+
"arguments": {}
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
"opcode": "markdownHeading",
|
|
309
|
+
"blockType": "REPORTER",
|
|
310
|
+
"text": "markdown [DOC] with heading level [LEVEL] [TEXT]",
|
|
311
|
+
"description": "Appends a Markdown heading and returns the same builder handle.",
|
|
312
|
+
"arguments": {
|
|
313
|
+
"DOC": {"type": "STRING", "defaultValue": "md:1"},
|
|
314
|
+
"LEVEL": {"type": "NUMBER", "defaultValue": 1},
|
|
315
|
+
"TEXT": {"type": "STRING", "defaultValue": "Title"}
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
"opcode": "markdownParagraph",
|
|
320
|
+
"blockType": "REPORTER",
|
|
321
|
+
"text": "markdown [DOC] with paragraph [TEXT]",
|
|
322
|
+
"description": "Appends a Markdown paragraph and returns the same builder handle.",
|
|
323
|
+
"arguments": {
|
|
324
|
+
"DOC": {"type": "STRING", "defaultValue": "md:1"},
|
|
325
|
+
"TEXT": {"type": "STRING", "defaultValue": "Hello"}
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
"opcode": "markdownBullet",
|
|
330
|
+
"blockType": "REPORTER",
|
|
331
|
+
"text": "markdown [DOC] with bullet [TEXT]",
|
|
332
|
+
"description": "Appends a Markdown bullet and returns the same builder handle.",
|
|
333
|
+
"arguments": {
|
|
334
|
+
"DOC": {"type": "STRING", "defaultValue": "md:1"},
|
|
335
|
+
"TEXT": {"type": "STRING", "defaultValue": "Item"}
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
"opcode": "markdownCodeBlock",
|
|
340
|
+
"blockType": "REPORTER",
|
|
341
|
+
"text": "markdown [DOC] with code [CODE] language [LANG]",
|
|
342
|
+
"description": "Appends a fenced Markdown code block and returns the same builder handle.",
|
|
343
|
+
"arguments": {
|
|
344
|
+
"DOC": {"type": "STRING", "defaultValue": "md:1"},
|
|
345
|
+
"CODE": {"type": "STRING", "defaultValue": "console.log('hello')"},
|
|
346
|
+
"LANG": {"type": "STRING", "defaultValue": "js"}
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
"opcode": "renderMarkdown",
|
|
351
|
+
"blockType": "REPORTER",
|
|
352
|
+
"text": "render markdown [DOC]",
|
|
353
|
+
"description": "Renders a Markdown builder handle to Markdown text.",
|
|
354
|
+
"arguments": {
|
|
355
|
+
"DOC": {"type": "STRING", "defaultValue": "md:1"}
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
"opcode": "newHtmlElement",
|
|
360
|
+
"blockType": "REPORTER",
|
|
361
|
+
"text": "new HTML element [TAG]",
|
|
362
|
+
"description": "Creates an HTML element builder handle.",
|
|
363
|
+
"arguments": {
|
|
364
|
+
"TAG": {"type": "STRING", "defaultValue": "div"}
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
"opcode": "htmlText",
|
|
369
|
+
"blockType": "REPORTER",
|
|
370
|
+
"text": "HTML text [TEXT]",
|
|
371
|
+
"description": "Creates an escaped HTML text node handle.",
|
|
372
|
+
"arguments": {
|
|
373
|
+
"TEXT": {"type": "STRING", "defaultValue": "Hello"}
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
"opcode": "htmlSetAttribute",
|
|
378
|
+
"blockType": "REPORTER",
|
|
379
|
+
"text": "HTML [NODE] with attribute [NAME] [VALUE]",
|
|
380
|
+
"description": "Sets an escaped attribute on an HTML element and returns the same handle.",
|
|
381
|
+
"arguments": {
|
|
382
|
+
"NODE": {"type": "STRING", "defaultValue": "html:1"},
|
|
383
|
+
"NAME": {"type": "STRING", "defaultValue": "class"},
|
|
384
|
+
"VALUE": {"type": "STRING", "defaultValue": "content"}
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
"opcode": "htmlAppendChild",
|
|
389
|
+
"blockType": "REPORTER",
|
|
390
|
+
"text": "HTML [PARENT] with child [CHILD]",
|
|
391
|
+
"description": "Appends a child node to an HTML element and returns the parent handle.",
|
|
392
|
+
"arguments": {
|
|
393
|
+
"PARENT": {"type": "STRING", "defaultValue": "html:1"},
|
|
394
|
+
"CHILD": {"type": "STRING", "defaultValue": "html:2"}
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
"opcode": "renderHtml",
|
|
399
|
+
"blockType": "REPORTER",
|
|
400
|
+
"text": "render HTML [NODE]",
|
|
401
|
+
"description": "Renders an HTML node handle to an HTML fragment.",
|
|
402
|
+
"arguments": {
|
|
403
|
+
"NODE": {"type": "STRING", "defaultValue": "html:1"}
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
"opcode": "renderHtmlDocument",
|
|
408
|
+
"blockType": "REPORTER",
|
|
409
|
+
"text": "render HTML document title [TITLE] body [BODY]",
|
|
410
|
+
"description": "Renders a full HTML document from an HTML body node handle.",
|
|
411
|
+
"arguments": {
|
|
412
|
+
"TITLE": {"type": "STRING", "defaultValue": "Page"},
|
|
413
|
+
"BODY": {"type": "STRING", "defaultValue": "html:1"}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
]
|
|
417
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {readFileSync} from 'node:fs';
|
|
2
|
+
import {HtdigestFile} from './auth/digest-file.js';
|
|
3
|
+
import {startServer} from './server.js';
|
|
4
|
+
import type {CommunityServerOptions} from './community.js';
|
|
5
|
+
import type {DigestAuthOptions} from './auth/digest.js';
|
|
6
|
+
|
|
7
|
+
interface CliOptions {
|
|
8
|
+
hostname: string;
|
|
9
|
+
port: number;
|
|
10
|
+
community?: false | CommunityServerOptions;
|
|
11
|
+
authDigestFile?: string;
|
|
12
|
+
authRealm?: string;
|
|
13
|
+
tlsCert?: string;
|
|
14
|
+
tlsKey?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const options = parseArgs(process.argv.slice(2));
|
|
18
|
+
const server = startServer(toServerOptions(options));
|
|
19
|
+
|
|
20
|
+
console.log(
|
|
21
|
+
`turbowarp-http-server listening on ${options.tlsCert ? 'https' : 'http'}://${server.hostname}:${server.port}`
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
function shutdown(signal: string): void {
|
|
25
|
+
console.log(`Received ${signal}; shutting down.`);
|
|
26
|
+
server
|
|
27
|
+
.close()
|
|
28
|
+
.catch((error: unknown) => {
|
|
29
|
+
console.error(error);
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
})
|
|
32
|
+
.finally(() => {
|
|
33
|
+
process.exit();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
38
|
+
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
39
|
+
|
|
40
|
+
function parseArgs(args: readonly string[]): CliOptions {
|
|
41
|
+
const options: CliOptions = {
|
|
42
|
+
hostname: process.env.HOST ?? '127.0.0.1',
|
|
43
|
+
port: parsePort(process.env.PORT ?? '8787'),
|
|
44
|
+
community: isTruthy(process.env.COMMUNITY) ? {} : false
|
|
45
|
+
};
|
|
46
|
+
if (process.env.TURBOWARP_HTTP_DIGEST_FILE) {
|
|
47
|
+
options.authDigestFile = process.env.TURBOWARP_HTTP_DIGEST_FILE;
|
|
48
|
+
}
|
|
49
|
+
if (process.env.TURBOWARP_HTTP_DIGEST_REALM) {
|
|
50
|
+
options.authRealm = process.env.TURBOWARP_HTTP_DIGEST_REALM;
|
|
51
|
+
}
|
|
52
|
+
if (process.env.TURBOWARP_HTTP_TLS_CERT) {
|
|
53
|
+
options.tlsCert = process.env.TURBOWARP_HTTP_TLS_CERT;
|
|
54
|
+
}
|
|
55
|
+
if (process.env.TURBOWARP_HTTP_TLS_KEY) {
|
|
56
|
+
options.tlsKey = process.env.TURBOWARP_HTTP_TLS_KEY;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
60
|
+
const arg = args[index];
|
|
61
|
+
if (arg === '--host') {
|
|
62
|
+
options.hostname = requireValue(args, index, '--host');
|
|
63
|
+
index += 1;
|
|
64
|
+
} else if (arg === '--port') {
|
|
65
|
+
options.port = parsePort(requireValue(args, index, '--port'));
|
|
66
|
+
index += 1;
|
|
67
|
+
} else if (arg === '--community') {
|
|
68
|
+
options.community = {};
|
|
69
|
+
} else if (arg === '--auth-digest') {
|
|
70
|
+
options.authDigestFile = requireValue(args, index, '--auth-digest');
|
|
71
|
+
index += 1;
|
|
72
|
+
} else if (arg === '--auth-realm') {
|
|
73
|
+
options.authRealm = requireValue(args, index, '--auth-realm');
|
|
74
|
+
index += 1;
|
|
75
|
+
} else if (arg === '--tls-cert') {
|
|
76
|
+
options.tlsCert = requireValue(args, index, '--tls-cert');
|
|
77
|
+
index += 1;
|
|
78
|
+
} else if (arg === '--tls-key') {
|
|
79
|
+
options.tlsKey = requireValue(args, index, '--tls-key');
|
|
80
|
+
index += 1;
|
|
81
|
+
} else if (arg === '--help' || arg === '-h') {
|
|
82
|
+
printHelp();
|
|
83
|
+
process.exit(0);
|
|
84
|
+
} else {
|
|
85
|
+
throw new Error(`Unknown argument: ${arg}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (options.authDigestFile && !options.authRealm) {
|
|
90
|
+
throw new Error('--auth-realm is required when --auth-digest is specified.');
|
|
91
|
+
}
|
|
92
|
+
if (!options.authDigestFile && options.authRealm) {
|
|
93
|
+
throw new Error('--auth-digest is required when --auth-realm is specified.');
|
|
94
|
+
}
|
|
95
|
+
if (Boolean(options.tlsCert) !== Boolean(options.tlsKey)) {
|
|
96
|
+
throw new Error('--tls-cert and --tls-key must be specified together.');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return options;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function toServerOptions(options: CliOptions): Parameters<typeof startServer>[0] {
|
|
103
|
+
const serverOptions: Parameters<typeof startServer>[0] = {
|
|
104
|
+
hostname: options.hostname,
|
|
105
|
+
port: options.port
|
|
106
|
+
};
|
|
107
|
+
if (options.community !== undefined) serverOptions.community = options.community;
|
|
108
|
+
const digestAuth = toDigestAuthOptions(options);
|
|
109
|
+
if (digestAuth) serverOptions.digestAuth = digestAuth;
|
|
110
|
+
if (options.tlsCert && options.tlsKey) {
|
|
111
|
+
serverOptions.tls = {
|
|
112
|
+
cert: readFileSync(options.tlsCert),
|
|
113
|
+
key: readFileSync(options.tlsKey)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return serverOptions;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function toDigestAuthOptions(options: CliOptions): DigestAuthOptions | undefined {
|
|
120
|
+
if (!options.authDigestFile || !options.authRealm) return undefined;
|
|
121
|
+
return {
|
|
122
|
+
realm: options.authRealm,
|
|
123
|
+
credentials: new HtdigestFile(options.authDigestFile)
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function requireValue(args: readonly string[], index: number, name: string): string {
|
|
128
|
+
const value = args[index + 1];
|
|
129
|
+
if (value === undefined || value.startsWith('--')) {
|
|
130
|
+
throw new Error(`${name} requires a value.`);
|
|
131
|
+
}
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function parsePort(value: string): number {
|
|
136
|
+
const port = Number.parseInt(value, 10);
|
|
137
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
138
|
+
throw new Error(`Invalid port: ${value}`);
|
|
139
|
+
}
|
|
140
|
+
return port;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function isTruthy(value: string | undefined): boolean {
|
|
144
|
+
return value === '1' || value === 'true' || value === 'yes';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function printHelp(): void {
|
|
148
|
+
console.log(`Usage: turbowarp-http-server [--host <host>] [--port <port>]
|
|
149
|
+
|
|
150
|
+
Starts the companion HTTP/WebSocket bridge for the TurboWarp extension.
|
|
151
|
+
|
|
152
|
+
Options:
|
|
153
|
+
--host <host> Hostname or address to bind. Defaults to HOST or 127.0.0.1.
|
|
154
|
+
--port <port> TCP port to bind. Defaults to PORT or 8787.
|
|
155
|
+
--community Enable the learning-only Scratch-like community routes.
|
|
156
|
+
--auth-digest <file>
|
|
157
|
+
Enable HTTP Digest authentication using an htdigest file.
|
|
158
|
+
--auth-realm <realm>
|
|
159
|
+
HTTP Digest authentication realm.
|
|
160
|
+
--tls-cert <file>
|
|
161
|
+
Enable HTTPS with the certificate file.
|
|
162
|
+
--tls-key <file>
|
|
163
|
+
Enable HTTPS with the private key file.
|
|
164
|
+
-h, --help Show this help.
|
|
165
|
+
|
|
166
|
+
Environment:
|
|
167
|
+
TURBOWARP_HTTP_DIGEST_FILE
|
|
168
|
+
TURBOWARP_HTTP_DIGEST_REALM
|
|
169
|
+
TURBOWARP_HTTP_TLS_CERT
|
|
170
|
+
TURBOWARP_HTTP_TLS_KEY
|
|
171
|
+
`);
|
|
172
|
+
}
|