ext/web W7: finish network extension polish
Ship Cache-Control, 301 redirects, custom 404/500, sitemap/robots, and init unique/index so the web capability roadmap is complete for P0–P2. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
6808d56c9d
commit
323449c2c3
13 files changed
+920
-34
No files matched your search
+43
-3
@@ -151,6 +151,8 @@ Open a database handle. URL schemes: `sqlite:path` (default), `postgres://…` /
|
||||
+ `name`
|
||||
+ `fields`
|
||||
|
||||
Create a table from a schema table. Optional columns: `唯一`/`unique`, `索引`/`index` (creates UNIQUE / INDEX).
|
||||
|
||||
*url = self[^url]*
|
||||
**> web_db_init url=`url` name=`name` fields=`fields`**
|
||||
|
||||
@@ -438,16 +440,17 @@ Serve files from `dir` under `mount` (default `/static`). Path is resolved from
|
||||
+ `body_limit`=None
|
||||
+ `json`=None
|
||||
+ `access_log`=None
|
||||
+ `cache_control`=None
|
||||
|
||||
Each capability is declared as a data table and assembled at listen time. The `cors` parameter takes a `|允许来源|方法|头|暴露头|凭证|` table (one row per origin; an empty `允许来源` column means any origin). The `security` parameter takes a `|头|值|` response-header table (e.g. `X-Frame-Options`, `Content-Security-Policy`, `X-Content-Type-Options`, `Referrer-Policy`, `Strict-Transport-Security`). Set `compress` to `True` to gzip response bodies. `body_limit` is the max request body bytes (e.g. `1048576`). The `json` parameter takes a `|路径|方法|表|条件|排序|上限|` table of JSON API endpoints backed by DB queries (each returns `application/json`). Set `access_log` to `True` to log `METHOD path status duration_ms` on stderr.
|
||||
Each capability is declared as a data table and assembled at listen time. The `cors` parameter takes a `|允许来源|方法|头|暴露头|凭证|` table (one row per origin; an empty `允许来源` column means any origin). The `security` parameter takes a `|头|值|` response-header table (e.g. `X-Frame-Options`, `Content-Security-Policy`, `X-Content-Type-Options`, `Referrer-Policy`, `Strict-Transport-Security`). Set `compress` to `True` to gzip response bodies. `body_limit` is the max request body bytes (e.g. `1048576`). The `json` parameter takes a `|路径|方法|表|条件|排序|上限|` table of JSON API endpoints backed by DB queries (each returns `application/json`). Set `access_log` to `True` to log `METHOD path status duration_ms` on stderr. `cache_control` sets a global `Cache-Control` header (e.g. `public, max-age=3600`).
|
||||
|
||||
Tables stay as data; `configure` assembles them. 配置即数据、装配即函数.
|
||||
|
||||
**> web_app_middleware app=`self` cors=`cors` security=`security` compress=`compress` body_limit=`body_limit` json_routes=`json` access_log=`access_log`**
|
||||
**> web_app_middleware app=`self` cors=`cors` security=`security` compress=`compress` body_limit=`body_limit` json_routes=`json` access_log=`access_log` cache_control=`cache_control`**
|
||||
|
||||
## listen
|
||||
|
||||
Serve `/`, routed pages, `/_part/{id}` (home) and `{path}/_part/{id}` (routes), `/_form/{id}` (from mounts + page embeds), optional `/static` (or custom mount), optional `/admin`, and any `upload` / `download` / WebSocket routes.
|
||||
Serve `/`, routed pages, `/_part/{id}` (home) and `{path}/_part/{id}` (routes), `/_form/{id}` (from mounts + page embeds), optional `/static` (or custom mount), optional `/admin`, upload/download/WebSocket/RSS/sitemap/robots routes, redirects, and a custom 404 fallback. Production HTTPS should terminate at a reverse proxy; set `cookie_secure=True` when serving over TLS.
|
||||
|
||||
**> web_listen app=`self`**
|
||||
|
||||
@@ -481,6 +484,43 @@ Register an RSS 2.0 feed at `path` (e.g. `/feed.xml`) backed by a DB table.
|
||||
|
||||
**> web_app_route_rss app=`self` path=`path` table=`table` limit=`limit` order=`order` title=`title` link=`link` description=`description`**
|
||||
|
||||
## redirect
|
||||
+ `from`
|
||||
+ `to`
|
||||
+ `permanent`=False
|
||||
|
||||
Register a redirect from `from` to `to`. `permanent=True` issues HTTP 301; otherwise 307.
|
||||
|
||||
**> web_app_redirect app=`self` from=`from` to=`to` permanent=`permanent`**
|
||||
|
||||
## error_page
|
||||
+ `status`=404
|
||||
+ `page`
|
||||
|
||||
Bind an assembled page for HTTP `404` or `500` responses.
|
||||
|
||||
**> web_app_error_page app=`self` status=`status` page=`page`**
|
||||
|
||||
## sitemap
|
||||
+ `path`=/sitemap.xml
|
||||
+ `base`=""
|
||||
+ `table`=None
|
||||
+ `loc`=path
|
||||
+ `limit`=1000
|
||||
+ `items`=None
|
||||
|
||||
Serve `sitemap.xml`. Prefer `table` + `loc` column from the DB, or pass an `items` table with `loc`/`路径` rows.
|
||||
|
||||
**> web_app_sitemap app=`self` path=`path` base=`base` table=`table` loc=`loc` limit=`limit` items=`items`**
|
||||
|
||||
## robots
|
||||
+ `body`=None
|
||||
+ `sitemap`=None
|
||||
|
||||
Serve `/robots.txt`. Omit `body` to emit a default Allow-all file, optionally with a `Sitemap:` line.
|
||||
|
||||
**> web_app_robots app=`self` body=`body` sitemap=`sitemap`**
|
||||
|
||||
## upload
|
||||
+ `path`=/_upload
|
||||
+ `field`=file
|
||||
|
||||
+43
-3
@@ -138,6 +138,8 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
|
||||
+ `名`
|
||||
+ `字段`
|
||||
|
||||
从表结构创建表。可选列:`唯一`/`unique`、`索引`/`index`。
|
||||
|
||||
*url = self[^url]*
|
||||
**> web_db_init url=`url` name=`名` fields=`字段`**
|
||||
|
||||
@@ -420,16 +422,17 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
|
||||
+ `请求体上限`=None
|
||||
+ `接口`=None
|
||||
+ `访问日志`=None
|
||||
+ `缓存控制`=None
|
||||
|
||||
每项能力用数据表声明,`监听` 时统一装配。`跨域` 参数接受 `|允许来源|方法|头|暴露头|凭证|` 表(每来源一行;`允许来源` 留空表示允许任意来源)。`安全` 参数接受 `|头|值|` 响应头表(如 `X-Frame-Options`、`Content-Security-Policy`、`X-Content-Type-Options`、`Referrer-Policy`、`Strict-Transport-Security`)。`压缩` 为 `真` 时对响应体做 gzip 压缩。`请求体上限` 是请求体最大字节数(如 `1048576`)。`接口` 参数接受 `|路径|方法|表|条件|排序|上限|` JSON API 端点表(每个返回 `application/json`)。`访问日志` 为 `真` 时在 stderr 打印 `METHOD path status duration_ms`。
|
||||
每项能力用数据表声明,`监听` 时统一装配。`跨域` 参数接受 `|允许来源|方法|头|暴露头|凭证|` 表(每来源一行;`允许来源` 留空表示允许任意来源)。`安全` 参数接受 `|头|值|` 响应头表(如 `X-Frame-Options`、`Content-Security-Policy`、`X-Content-Type-Options`、`Referrer-Policy`、`Strict-Transport-Security`)。`压缩` 为 `真` 时对响应体做 gzip 压缩。`请求体上限` 是请求体最大字节数(如 `1048576`)。`接口` 参数接受 `|路径|方法|表|条件|排序|上限|` JSON API 端点表(每个返回 `application/json`)。`访问日志` 为 `真` 时在 stderr 打印 `METHOD path status duration_ms`。`缓存控制` 设置全局 `Cache-Control`(如 `public, max-age=3600`)。
|
||||
|
||||
表仍是数据,`装配` 把它们变成能力。配置即数据、装配即函数。
|
||||
|
||||
**> web_app_middleware app=`self` cors=`跨域` security=`安全` compress=`压缩` body_limit=`请求体上限` json_routes=`接口` access_log=`访问日志`**
|
||||
**> web_app_middleware app=`self` cors=`跨域` security=`安全` compress=`压缩` body_limit=`请求体上限` json_routes=`接口` access_log=`访问日志` cache_control=`缓存控制`**
|
||||
|
||||
## 监听
|
||||
|
||||
提供 `/`、路由页、首页 `/_part/{id}`、路由 `{路径}/_part/{id}`、`/_form/{id}`、可选静态目录、可选 `/admin`,以及已挂载的 `上传` / `下载` / WebSocket 路由。
|
||||
提供 `/`、路由页、首页 `/_part/{id}`、路由 `{路径}/_part/{id}`、`/_form/{id}`、可选静态目录、可选 `/admin`,上传/下载/WebSocket/RSS/sitemap/robots、重定向,以及自定义 404。生产 HTTPS 请在反向代理终止;启用 TLS 时设 `cookie_secure`。
|
||||
|
||||
**> web_listen app=`self`**
|
||||
|
||||
@@ -463,6 +466,43 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
|
||||
|
||||
**> web_app_route_rss app=`self` path=`路径` table=`表` limit=`上限` order=`排序` title=`标题` link=`链接` description=`描述`**
|
||||
|
||||
## 重定向
|
||||
+ `来源`
|
||||
+ `目标`
|
||||
+ `永久`=假
|
||||
|
||||
将 `来源` 重定向到 `目标`。`永久=真` 返回 301,否则 307。
|
||||
|
||||
**> web_app_redirect app=`self` from=`来源` to=`目标` permanent=`永久`**
|
||||
|
||||
## 错误页
|
||||
+ `状态`=404
|
||||
+ `页面`
|
||||
|
||||
为 HTTP `404` 或 `500` 绑定已装配页面。
|
||||
|
||||
**> web_app_error_page app=`self` status=`状态` page=`页面`**
|
||||
|
||||
## 站点地图
|
||||
+ `路径`=/sitemap.xml
|
||||
+ `基址`=""
|
||||
+ `表`=None
|
||||
+ `定位列`=path
|
||||
+ `上限`=1000
|
||||
+ `条目`=None
|
||||
|
||||
提供 sitemap.xml。优先用数据库 `表` + `定位列`,或传入带 `loc`/`路径` 的 `条目` 表。
|
||||
|
||||
**> web_app_sitemap app=`self` path=`路径` base=`基址` table=`表` loc=`定位列` limit=`上限` items=`条目`**
|
||||
|
||||
## 爬虫协议
|
||||
+ `正文`=None
|
||||
+ `站点地图`=None
|
||||
|
||||
提供 `/robots.txt`。省略 `正文` 时生成默认 Allow-all,可附带 `Sitemap:` 行。
|
||||
|
||||
**> web_app_robots app=`self` body=`正文` sitemap=`站点地图`**
|
||||
|
||||
## 上传
|
||||
+ `路径`=/_upload
|
||||
+ `字段`=file
|
||||
|
||||
Reference in new issue
Block a user