@x1a0f3n9/dsh-host-frontend-static 0.1.5-rc.3
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 +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +117 -0
- package/README.zh.md +117 -0
- package/lib/index.js +99 -0
- package/lib/types/index.d.ts +44 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.i18n.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
|
2
|
+
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
|
+
# after editing either side, bring the other along and re-record with:
|
|
4
|
+
# pnpm run verify-translation-pairing --write packages/host/frontend-static/README.md
|
|
5
|
+
README.md: e616c048119fc1ce75ad29b002c3298b84169af9
|
|
6
|
+
README.zh.md: 6cf55bb6d82f665754767f0a8c5b9cc68d8236d6
|
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "SPA dist server for the Web shell: claims the webserver fallback seat and serves the built frontend with traversal rejection and SPA index fallback."
|
|
3
|
+
kind: "package-reference"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @x1a0f3n9/dsh-host-frontend-static
|
|
7
|
+
|
|
8
|
+
English | [中文](README.zh.md)
|
|
9
|
+
|
|
10
|
+
## Summary
|
|
11
|
+
|
|
12
|
+
Serve the built Web shell to browsers from its configured distribution directory. The root and configured index path render the bootstrapped index; existing assets are served directly, while missing or non-file paths return 404, traversal returns 403, and unsupported methods return 405. Index access requires a valid process token or browser cookie, but static assets remain public. Only one instance can handle unmatched routes at a time; a second activation fails, and unloading the active instance makes unmatched requests return 404.
|
|
13
|
+
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
- [Use this package](#use-this-package)
|
|
17
|
+
- [Understand the implementation](#understand-the-implementation)
|
|
18
|
+
- [Further Exploration](#further-exploration)
|
|
19
|
+
- [Model Experience](#model-experience)
|
|
20
|
+
- [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
|
|
21
|
+
- [Dev Note](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
<a id="use-this-package"></a>
|
|
26
|
+
## Use this package
|
|
27
|
+
|
|
28
|
+
Compose this plugin in a browser-facing host that serves the built Web shell: it claims the webserver's fallback seat and answers every request no named route matches. It needs one config value — where the built frontend's `index.html` lives.
|
|
29
|
+
|
|
30
|
+
### Minimal configuration
|
|
31
|
+
|
|
32
|
+
```yaml
|
|
33
|
+
- name: '@x1a0f3n9/dsh-host-frontend-static'
|
|
34
|
+
config:
|
|
35
|
+
distIndex: /absolute/path/to/dist/index.html
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`distIndex` is an assembly fact of the composing application: [`dsh-web-app`](../../bundle/web-app/README.md) resolves it through the frontend package's exports and mounts this plugin; a deployment never hardcodes it.
|
|
39
|
+
|
|
40
|
+
### What the server enforces
|
|
41
|
+
|
|
42
|
+
Requests are served from the dist root (the directory containing `distIndex`). The dist root and the configured index path render `index.html` with HTTP 200; any other existing file is served directly with its MIME type, and unknown extensions ship as `application/octet-stream`. A path that resolves outside the root is rejected with 403, so a crafted path cannot read files above the dist. An absent or non-file target inside the dist root — a missing file, a directory, or a missing configured index — returns an empty 404. Non-GET/HEAD requests without a matching named route are answered 405. Every successful index response is rendered through the webserver's `renderIndex`, so the boot manifest reaches the page on `/` and on the configured index path.
|
|
43
|
+
|
|
44
|
+
Root and configured-index responses call `ctx.connection.authorizeIndex` before reading HTML. A valid process token receives a 303 redirect plus the persistent browser cookie; an existing valid cookie serves the index; every other index request receives the Connection-owned 401 response. Non-index files remain public static assets. Connection owns the token, cookie, expiry, and signing-record semantics.
|
|
45
|
+
|
|
46
|
+
### Observable failures
|
|
47
|
+
|
|
48
|
+
Traversal returns 403 rather than an error page. An absent or non-file target inside the dist root returns an empty 404, so a stale link or a mistyped pathname is an explicit failure rather than a silent SPA fallback. Claiming the seat twice throws, and while the seat is unclaimed the webserver answers 404 — which is what a browser sees if this plugin's fiber is disposed.
|
|
49
|
+
|
|
50
|
+
-----
|
|
51
|
+
|
|
52
|
+
<a id="understand-the-implementation"></a>
|
|
53
|
+
## Understand the implementation
|
|
54
|
+
|
|
55
|
+
<details>
|
|
56
|
+
<summary>Implementation internals — click to expand</summary>
|
|
57
|
+
|
|
58
|
+
### Design concept
|
|
59
|
+
|
|
60
|
+
The package is one function plugin around `serveStatic`: `apply` resolves the dist root from `distIndex`, builds a `renderIndex` closure that runs `ctx.webServer.renderIndex` over the raw `index.html`, and registers the fallback handler under an effect scope. The seat is single-owner by the webserver's contract — a second registration throws — and effect-scoped, so disposing the fiber releases the seat.
|
|
61
|
+
|
|
62
|
+
### The traversal fence
|
|
63
|
+
|
|
64
|
+
`serveStatic` normalizes the requested pathname and joins it to the dist root, then requires the target to be the root itself or stay under it. The check uses `sep` rather than `/` because `resolve()` emits backslash paths on Windows, where a `/` suffix would reject every legitimate subpath as traversal.
|
|
65
|
+
|
|
66
|
+
### Source map
|
|
67
|
+
|
|
68
|
+
| File | Role |
|
|
69
|
+
|---|---|
|
|
70
|
+
| [`src/index.ts`](src/index.ts) | `serveStatic` and `apply`: fallback claim, traversal rejection, index rendering, MIME table |
|
|
71
|
+
|
|
72
|
+
</details>
|
|
73
|
+
|
|
74
|
+
-----
|
|
75
|
+
|
|
76
|
+
<a id="further-exploration"></a>
|
|
77
|
+
## Further Exploration
|
|
78
|
+
|
|
79
|
+
Read these when the serving contract is not enough: the seat owner's contract, then the composition that resolves the dist and the subsystem reference.
|
|
80
|
+
|
|
81
|
+
- [Webserver](../webserver/README.md) — the fallback seat this plugin claims and the index taps it runs.
|
|
82
|
+
- [dsh-web-app bundle](../../bundle/web-app/README.md) — the application that resolves `distIndex` and mounts this plugin.
|
|
83
|
+
- [HTTP server subsystem](../../../docs/subsystems/web-server.md) — how the fallback seat fits the route tables.
|
|
84
|
+
- [Generated configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-host-frontend-static) — every accepted config field and its source declaration.
|
|
85
|
+
|
|
86
|
+
-----
|
|
87
|
+
|
|
88
|
+
<a id="model-experience"></a>
|
|
89
|
+
## Model Experience
|
|
90
|
+
|
|
91
|
+
None, as the SPA dist server answers browser asset requests and registers nothing model-facing.
|
|
92
|
+
|
|
93
|
+
#### KV Cache effect
|
|
94
|
+
|
|
95
|
+
None; this package neither assembles nor sends a provider request.
|
|
96
|
+
|
|
97
|
+
## Known Limitations and Deferred Work
|
|
98
|
+
|
|
99
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
These limits define when a served asset class is not yet covered. They are current package constraints, not a task backlog.
|
|
103
|
+
|
|
104
|
+
- **The starter MIME table is minimal** — it covers the Vite-emitted asset set plus the shipped PWA manifest; other extensions fall back to `application/octet-stream` until an asset class ships.
|
|
105
|
+
- **Pathname routing is explicit** — the current client enters through the root or configured index path and has no History API pathname routes. Adding one requires an explicit server rule and real-composition coverage rather than a broad fallback for every miss.
|
|
106
|
+
|
|
107
|
+
<a id="dev-note"></a>
|
|
108
|
+
### Dev Note
|
|
109
|
+
|
|
110
|
+
<details>
|
|
111
|
+
<summary>Working context for maintainers — click to expand</summary>
|
|
112
|
+
|
|
113
|
+
None.
|
|
114
|
+
|
|
115
|
+
</details>
|
|
116
|
+
|
|
117
|
+
**Runtime invariant:** No companion is published. The only owned relation is the single fallback seat, which cannot be probed from the teardown stream — `internal/plugin` fires before the disposing fiber's effects run, so the legitimate owner still holds the seat at notification time and any claim probe would false-positive on every correct disposal (unlike the webserver companion, whose reserved-path probes never collide with a live registration). The seat's register/release symmetry is covered by the package's real-composition HMR-safety test instead.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Web 壳的 SPA dist 服务器:占据 webserver 回退席位,以遍历拒绝与 SPA index 回退服务已构建的前端。"
|
|
3
|
+
kind: "package-reference"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @x1a0f3n9/dsh-host-frontend-static
|
|
7
|
+
|
|
8
|
+
[English](README.md) | 中文
|
|
9
|
+
|
|
10
|
+
## 概述
|
|
11
|
+
|
|
12
|
+
从配置的发布目录向浏览器提供已构建的 Web 壳。根路径与配置的 index 路径渲染包含启动信息的 index;已有资产直接提供,而缺失或非文件路径返回 404、路径遍历返回 403、不支持的方法返回 405。访问 index 需要有效的进程 token 或浏览器 cookie,但静态资产仍可公开访问。同一时间只能有一个实例处理未匹配的路由;第二个实例启动失败,卸载活动实例后,未匹配的请求返回 404。
|
|
13
|
+
|
|
14
|
+
## 目录
|
|
15
|
+
|
|
16
|
+
- [使用本包](#use-this-package)
|
|
17
|
+
- [理解实现](#understand-the-implementation)
|
|
18
|
+
- [进一步探索](#further-exploration)
|
|
19
|
+
- [模型体验](#model-experience)
|
|
20
|
+
- [已知限制与延期工作](#known-limitations-and-deferred-work)
|
|
21
|
+
- [开发备注](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
<a id="use-this-package"></a>
|
|
26
|
+
## 使用本包
|
|
27
|
+
|
|
28
|
+
在服务已构建 Web 壳的浏览器宿主中组合本插件:它占据 webserver 的回退席位,并应答所有未被具名路由命中的请求。它只需要一个配置值——已构建前端的 `index.html` 位于何处。
|
|
29
|
+
|
|
30
|
+
### 最小配置
|
|
31
|
+
|
|
32
|
+
```yaml
|
|
33
|
+
- name: '@x1a0f3n9/dsh-host-frontend-static'
|
|
34
|
+
config:
|
|
35
|
+
distIndex: /absolute/path/to/dist/index.html
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`distIndex` 是组合应用的组装事实:[`dsh-web-app`](../../bundle/web-app/README.zh.md) 通过前端包的 exports 解析它并挂载本插件;部署绝不硬编码它。
|
|
39
|
+
|
|
40
|
+
### 服务器实施的约束
|
|
41
|
+
|
|
42
|
+
请求从 dist 根目录(包含 `distIndex` 的目录)提供。dist 根目录与配置的 index 路径以 HTTP 200 渲染 `index.html`;任何其他已有文件按自身 MIME 类型直接提供,未知扩展名按 `application/octet-stream` 提供。解析到根目录之外的路径以 403 拒绝,因此精心构造的路径无法读取 dist 之上的文件。dist 根目录内不存在或不是文件的目标——文件缺失、目录或配置的 index 缺失——返回空 404。没有匹配具名路由的非 GET/HEAD 请求返回 405。每个成功的 index 响应都经 webserver 的 `renderIndex` 渲染,因此启动 manifest(元数据清单)会通过 `/` 与配置的 index 路径送达页面。
|
|
43
|
+
|
|
44
|
+
根路径与配置的 index 响应会在读取 HTML 前调用 `ctx.connection.authorizeIndex`。有效进程 token 会得到 303 重定向与持久浏览器 cookie;已有有效 cookie 时直接提供 index;其他 index 请求得到 Connection 所有的 401 响应。非 index 文件仍是公开静态资源。Token、cookie、过期时间与签名记录语义都归 Connection 所有。
|
|
45
|
+
|
|
46
|
+
### 可观察的失败
|
|
47
|
+
|
|
48
|
+
遍历返回 403 而不是错误页。dist 根目录内不存在或不是文件的目标返回空 404,因此失效链接或拼错的 pathname 是显式失败,而不是静默的 SPA 回退。第二次占据席位会抛错,而席位无人占据时 webserver 返回 404——本插件的 fiber 被 dispose(资源释放)后,浏览器看到的就是该响应。
|
|
49
|
+
|
|
50
|
+
-----
|
|
51
|
+
|
|
52
|
+
<a id="understand-the-implementation"></a>
|
|
53
|
+
## 理解实现
|
|
54
|
+
|
|
55
|
+
<details>
|
|
56
|
+
<summary>实现细节——点击展开</summary>
|
|
57
|
+
|
|
58
|
+
### 设计理念
|
|
59
|
+
|
|
60
|
+
本包是围绕 `serveStatic` 的一个函数插件:`apply` 从 `distIndex` 解析出 dist 根目录,构建一个对原始 `index.html` 运行 `ctx.webServer.renderIndex` 的 `renderIndex` 闭包,并在 effect 作用域下注册回退 handler。按 webserver 的约定,席位只有单一所有者——第二次注册会抛错——且受 effect 作用域约束,因此 dispose fiber 即释放席位。
|
|
61
|
+
|
|
62
|
+
### 遍历栅栏
|
|
63
|
+
|
|
64
|
+
`serveStatic` 规范化请求的 pathname 并拼接到 dist 根目录,然后要求目标就是根目录本身或保持在它之下。检查使用 `sep` 而非 `/`,因为 `resolve()` 在 Windows 上输出反斜杠路径,此时 `/` 后缀会把每个合法子路径都当作遍历拒绝。
|
|
65
|
+
|
|
66
|
+
### 源码地图
|
|
67
|
+
|
|
68
|
+
| 文件 | 职责 |
|
|
69
|
+
|---|---|
|
|
70
|
+
| [`src/index.ts`](src/index.ts) | `serveStatic` 与 `apply`:回退占据、遍历拒绝、index 渲染、MIME 表 |
|
|
71
|
+
|
|
72
|
+
</details>
|
|
73
|
+
|
|
74
|
+
-----
|
|
75
|
+
|
|
76
|
+
<a id="further-exploration"></a>
|
|
77
|
+
## 进一步探索
|
|
78
|
+
|
|
79
|
+
当服务约定不够用时阅读以下内容:先看席位所有者的约定,再看解析 dist 的组合与子系统参考。
|
|
80
|
+
|
|
81
|
+
- [Webserver](../webserver/README.zh.md)——本插件占据的回退席位与它运行的 index 转换器。
|
|
82
|
+
- [dsh-web-app 组合包](../../bundle/web-app/README.zh.md)——解析 `distIndex` 并挂载本插件的应用。
|
|
83
|
+
- [HTTP 服务器子系统](../../../docs/subsystems/web-server.zh.md)——回退席位如何融入路由表。
|
|
84
|
+
- [生成配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-host-frontend-static)——每个受支持配置字段及其源声明。
|
|
85
|
+
|
|
86
|
+
-----
|
|
87
|
+
|
|
88
|
+
<a id="model-experience"></a>
|
|
89
|
+
## 模型体验
|
|
90
|
+
|
|
91
|
+
无。该 SPA dist 服务器只应答浏览器资产请求,不注册任何面向模型的内容。
|
|
92
|
+
|
|
93
|
+
#### KV Cache 影响
|
|
94
|
+
|
|
95
|
+
无;该包既不组装也不发送提供方请求。
|
|
96
|
+
|
|
97
|
+
## 已知限制与延期工作
|
|
98
|
+
|
|
99
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
这些限制说明某个资产类别何时尚未被覆盖。它们是当前包约束,不是任务积压。
|
|
103
|
+
|
|
104
|
+
- **初始 MIME 表很精简**:它覆盖 Vite 输出的资产集合及实际交付的 PWA manifest;其他扩展名在相应资产类别发布前都会回退到 `application/octet-stream`。
|
|
105
|
+
- **Pathname 路由是显式声明**——当前客户端从根目录或配置的 index 路径进入,没有 History API pathname 路由。新增一条需要显式服务器规则与真实组合覆盖,而不是对每次未命中做宽泛回退。
|
|
106
|
+
|
|
107
|
+
<a id="dev-note"></a>
|
|
108
|
+
### 开发备注
|
|
109
|
+
|
|
110
|
+
<details>
|
|
111
|
+
<summary>维护者的工作上下文——点击展开</summary>
|
|
112
|
+
|
|
113
|
+
无。
|
|
114
|
+
|
|
115
|
+
</details>
|
|
116
|
+
|
|
117
|
+
**运行时不变式:** 不发布伴生入口。唯一受本包所有的关系是单个回退席位,但无法从 teardown 流中探测它:`internal/plugin` 在正在释放的 fiber 执行 effect disposer 前触发,因此通知发出时合法所有者仍占据席位,任何占位探测都会把每次正确释放误报为失败;这不同于 webserver companion 对保留路径的探测,后者不会与存活注册冲突。席位的注册/释放对称性由本包真实组合的 HMR(热模块替换)安全测试覆盖。
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, extname, join, normalize, resolve, sep } from "node:path";
|
|
3
|
+
import z from "@deepseek-ai/schemastery";
|
|
4
|
+
//#region lib/types/index.js
|
|
5
|
+
/**
|
|
6
|
+
* @x1a0f3n9/dsh-host-frontend-static — SPA dist server over the webserver
|
|
7
|
+
* fallback seat: serves the built frontend directory with explicit index
|
|
8
|
+
* entry points. A readable index renders at the dist root and configured index
|
|
9
|
+
* path; missing paths return 404, traversal outside the dist root is 403,
|
|
10
|
+
* unknown extensions ship as octet-stream, and non-GET/HEAD is 405. Every
|
|
11
|
+
* index response first passes Connection's browser authentication, then the
|
|
12
|
+
* webserver's index render (structured injection rows, then raw taps).
|
|
13
|
+
* Non-index assets stay public. The dist location is workspace knowledge of
|
|
14
|
+
* the composing application, so `distIndex` is typically supplied through a
|
|
15
|
+
* `!!js` expression, never hardcoded by a deployment.
|
|
16
|
+
* @module @x1a0f3n9/dsh-host-frontend-static
|
|
17
|
+
*/
|
|
18
|
+
/** Stable Cordis plugin name. */
|
|
19
|
+
const name = "frontend-static";
|
|
20
|
+
/** Services required before the authenticated fallback seat can be claimed. */
|
|
21
|
+
const inject = ["webServer", "connection"];
|
|
22
|
+
const Config = z.object({ distIndex: z.string().required() });
|
|
23
|
+
const HTML_MIME = "text/html; charset=utf-8";
|
|
24
|
+
const MIME = {
|
|
25
|
+
".html": HTML_MIME,
|
|
26
|
+
".js": "text/javascript; charset=utf-8",
|
|
27
|
+
".css": "text/css; charset=utf-8",
|
|
28
|
+
".svg": "image/svg+xml",
|
|
29
|
+
".json": "application/json",
|
|
30
|
+
".map": "application/json",
|
|
31
|
+
".webmanifest": "application/manifest+json",
|
|
32
|
+
".gz": "application/gzip"
|
|
33
|
+
};
|
|
34
|
+
const STATIC_MISS_CODES = new Set([
|
|
35
|
+
"ENOENT",
|
|
36
|
+
"EISDIR",
|
|
37
|
+
"ENOTDIR"
|
|
38
|
+
]);
|
|
39
|
+
/**
|
|
40
|
+
* Serve one GET/HEAD static request from the dist root.
|
|
41
|
+
* @param pathname - decoded URL pathname of the request.
|
|
42
|
+
* @param res - the node:http response to write.
|
|
43
|
+
* @param distRoot - absolute dist root directory (resolved by the caller).
|
|
44
|
+
* @param distIndex - absolute path of index.html inside distRoot.
|
|
45
|
+
* @param authorizeIndex - authenticates an index response before its bytes are read.
|
|
46
|
+
* @param renderIndex - produces the index.html body (structured injection
|
|
47
|
+
* rendering) for the dist root and configured index path.
|
|
48
|
+
*/
|
|
49
|
+
async function serveStatic(pathname, res, distRoot, distIndex, authorizeIndex, renderIndex) {
|
|
50
|
+
const target = resolve(normalize(join(distRoot, pathname)));
|
|
51
|
+
if (target !== distRoot && !target.startsWith(distRoot + sep)) {
|
|
52
|
+
res.writeHead(403);
|
|
53
|
+
res.end();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
let body;
|
|
57
|
+
let type;
|
|
58
|
+
try {
|
|
59
|
+
if (target === distRoot || target === distIndex) {
|
|
60
|
+
if (!authorizeIndex()) return;
|
|
61
|
+
body = await renderIndex();
|
|
62
|
+
type = HTML_MIME;
|
|
63
|
+
} else {
|
|
64
|
+
body = await readFile(target);
|
|
65
|
+
type = MIME[extname(target)] ?? "application/octet-stream";
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (!STATIC_MISS_CODES.has(error.code)) throw error;
|
|
69
|
+
res.writeHead(404);
|
|
70
|
+
res.end();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
res.writeHead(200, { "content-type": type });
|
|
74
|
+
res.end(body);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Claim the webserver fallback seat and serve the dist.
|
|
78
|
+
* @param ctx - plugin context carrying the webServer service.
|
|
79
|
+
* @param config - validated {@link Config}.
|
|
80
|
+
*/
|
|
81
|
+
function apply(ctx, config) {
|
|
82
|
+
const distIndex = config.distIndex;
|
|
83
|
+
const distRoot = dirname(distIndex);
|
|
84
|
+
const renderIndex = async () => {
|
|
85
|
+
return ctx.webServer.renderIndex(await readFile(distIndex, "utf8")).replace(/<head(?:\s[^>]*)?>/i, (open) => `${open}<base href="/">`);
|
|
86
|
+
};
|
|
87
|
+
ctx.effect(() => ctx.webServer.registerFallback(async (req, res) => {
|
|
88
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
89
|
+
res.writeHead(405);
|
|
90
|
+
res.end();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
/* v8 ignore next -- node:http always sets url on server requests */
|
|
94
|
+
const rawPath = new URL(req.url ?? "/", "http://x").pathname;
|
|
95
|
+
await serveStatic(decodeURIComponent(rawPath), res, distRoot, distIndex, () => ctx.connection.authorizeIndex(req, res), renderIndex);
|
|
96
|
+
}), "frontend-static: fallback seat");
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
export { Config, apply, inject, name, serveStatic };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @x1a0f3n9/dsh-host-frontend-static — SPA dist server over the webserver
|
|
3
|
+
* fallback seat: serves the built frontend directory with explicit index
|
|
4
|
+
* entry points. A readable index renders at the dist root and configured index
|
|
5
|
+
* path; missing paths return 404, traversal outside the dist root is 403,
|
|
6
|
+
* unknown extensions ship as octet-stream, and non-GET/HEAD is 405. Every
|
|
7
|
+
* index response first passes Connection's browser authentication, then the
|
|
8
|
+
* webserver's index render (structured injection rows, then raw taps).
|
|
9
|
+
* Non-index assets stay public. The dist location is workspace knowledge of
|
|
10
|
+
* the composing application, so `distIndex` is typically supplied through a
|
|
11
|
+
* `!!js` expression, never hardcoded by a deployment.
|
|
12
|
+
* @module @x1a0f3n9/dsh-host-frontend-static
|
|
13
|
+
*/
|
|
14
|
+
import type { ServerResponse } from 'node:http';
|
|
15
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
16
|
+
import z from '@deepseek-ai/schemastery';
|
|
17
|
+
/** Stable Cordis plugin name. */
|
|
18
|
+
export declare const name = "frontend-static";
|
|
19
|
+
/** Services required before the authenticated fallback seat can be claimed. */
|
|
20
|
+
export declare const inject: string[];
|
|
21
|
+
/** Plugin config: the dist anchor. */
|
|
22
|
+
export interface Config {
|
|
23
|
+
/** Absolute path of index.html inside the dist root. */
|
|
24
|
+
distIndex: string;
|
|
25
|
+
}
|
|
26
|
+
export declare const Config: z<Config>;
|
|
27
|
+
/**
|
|
28
|
+
* Serve one GET/HEAD static request from the dist root.
|
|
29
|
+
* @param pathname - decoded URL pathname of the request.
|
|
30
|
+
* @param res - the node:http response to write.
|
|
31
|
+
* @param distRoot - absolute dist root directory (resolved by the caller).
|
|
32
|
+
* @param distIndex - absolute path of index.html inside distRoot.
|
|
33
|
+
* @param authorizeIndex - authenticates an index response before its bytes are read.
|
|
34
|
+
* @param renderIndex - produces the index.html body (structured injection
|
|
35
|
+
* rendering) for the dist root and configured index path.
|
|
36
|
+
*/
|
|
37
|
+
export declare function serveStatic(pathname: string, res: ServerResponse, distRoot: string, distIndex: string, authorizeIndex: () => boolean, renderIndex: () => Promise<string>): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Claim the webserver fallback seat and serve the dist.
|
|
40
|
+
* @param ctx - plugin context carrying the webServer service.
|
|
41
|
+
* @param config - validated {@link Config}.
|
|
42
|
+
*/
|
|
43
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@x1a0f3n9/dsh-host-frontend-static",
|
|
3
|
+
"description": "SPA dist server for the Web shell: owns the webserver fallback seat, serving explicit index entries and static assets with traversal rejection and 404 misses",
|
|
4
|
+
"version": "0.1.5-rc.3",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
|
|
11
|
+
"directory": "packages/host/frontend-static"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"types": "lib/types/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/types/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./src/*": "./src/*",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"lib/index.js",
|
|
26
|
+
"lib/types/**/*.d.ts"
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@x1a0f3n9/dsh-host-webserver": "^0.1.5-rc.3",
|
|
31
|
+
"@x1a0f3n9/dsh-client-connection": "^0.1.5-rc.3",
|
|
32
|
+
"@deepseek-ai/cordis": "^4.0.2"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@deepseek-ai/schemastery": "^3.18.2"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@deepseek-ai/cordis-plugin-loader": "^1.0.3",
|
|
39
|
+
"@x1a0f3n9/dsh-client-connection": "^0.1.5-rc.3",
|
|
40
|
+
"@x1a0f3n9/dsh-credentials-local": "^0.1.5-rc.3",
|
|
41
|
+
"@x1a0f3n9/dsh-host-webserver": "^0.1.5-rc.3",
|
|
42
|
+
"@deepseek-ai/cordis": "^4.0.2"
|
|
43
|
+
}
|
|
44
|
+
}
|