dsh-wtq-pool 1.0.1 → 1.0.2

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/docs/serve.cjs DELETED
@@ -1,74 +0,0 @@
1
- // Serve this repository over http://127.0.0.1 so the preview page opens in a
2
- // browser. The preview fetches the panel markup it mounts (browsers block that
3
- // under file://) and the panel's own CSP admits scripts only from its own
4
- // origin; an http origin satisfies both.
5
- //
6
- // node docs/serve.cjs # then open the printed URL
7
- // node docs/serve.cjs 8123 # pick the port
8
- //
9
- // Read-only, and bound to 127.0.0.1.
10
- const http = require('node:http')
11
- const fs = require('node:fs')
12
- const path = require('node:path')
13
-
14
- const ROOT = path.resolve(__dirname, '..')
15
- const PORT = Number(process.argv[2] || 8124)
16
-
17
- const TYPES = {
18
- '.html': 'text/html; charset=utf-8',
19
- '.js': 'text/javascript; charset=utf-8',
20
- '.mjs': 'text/javascript; charset=utf-8',
21
- '.css': 'text/css; charset=utf-8',
22
- '.json': 'application/json; charset=utf-8',
23
- '.png': 'image/png',
24
- '.svg': 'image/svg+xml',
25
- }
26
-
27
- http.createServer((req, res) => {
28
- // A request-target the parser cannot resolve also throws, and it does so
29
- // before the guards below run: same rule as the decode failures, answered
30
- // rather than allowed to kill the server.
31
- let url
32
- try {
33
- url = new URL(req.url, 'http://127.0.0.1')
34
- } catch {
35
- res.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' }).end('bad request')
36
- return
37
- }
38
- // The preview page lives in docs/, so '/' redirects into it: the page's
39
- // relative links (./preview-panel.html, ../renderer/panel.js) resolve against
40
- // the URL, and a rewritten body under the wrong path would 404 every one.
41
- if (url.pathname === '/') {
42
- res.writeHead(302, { location: '/docs/index.html' }).end()
43
- return
44
- }
45
- // A malformed percent-escape (`/%zz`) makes decodeURIComponent throw, and a
46
- // decoded NUL makes fs.readFile throw; both would kill the server from inside
47
- // this callback, so they answer 400 instead. The path guard below still treats
48
- // the decoded value as untrusted.
49
- let rel
50
- try {
51
- rel = decodeURIComponent(url.pathname).replace(/^\/+/, '')
52
- } catch {
53
- res.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' }).end('bad request: ' + url.pathname)
54
- return
55
- }
56
- if (rel.includes('\0')) {
57
- res.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' }).end('bad request: ' + url.pathname)
58
- return
59
- }
60
- const file = path.resolve(ROOT, rel)
61
- if (file !== ROOT && !file.startsWith(ROOT + path.sep)) {
62
- res.writeHead(403).end('forbidden')
63
- return
64
- }
65
- fs.readFile(file, (err, body) => {
66
- if (err) {
67
- res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' }).end('not found: ' + rel)
68
- return
69
- }
70
- res.writeHead(200, { 'content-type': TYPES[path.extname(file)] || 'application/octet-stream' }).end(body)
71
- })
72
- }).listen(PORT, '127.0.0.1', function () {
73
- console.log('preview: http://127.0.0.1:' + this.address().port + '/ (Ctrl+C to stop)')
74
- })