Migrate remaining footnote-style collection access in examples, public/structure, and ext/lib smokes to [key](base); teach link-index in structure pages and use bracket calls in the cafe journal example. Co-authored-by: Cursor <cursoragent@cursor.com>
3.1 KiB
title: web middleware smoke description: Offline assemble of CORS/security/compress/json middleware (no listen). import web:ext/web/web.mq.md import plugin:lib/plugin.mq.md import sys:lib/sys.mq.md
main
p = > plugin.native_path name="web"
p
plugin.load path=
p
sys.exit code=1
cors =
| 允许来源 | 方法 | 头 | 暴露头 | 凭证 |
|---|---|---|---|---|
| https://a.example | GET,POST | Content-Type,Authorization | X-Total | true |
| https://b.example | GET | Content-Type |
sec =
| 头 | 值 |
|---|---|
| X-Frame-Options | DENY |
| X-Content-Type-Options | nosniff |
| Content-Security-Policy | default-src 'self' |
api =
| 路径 | 方法 | 表 | 条件 | 排序 | 上限 |
|---|---|---|---|---|---|
| /api/posts | GET | articles | "-created_at" | 20 | |
| /api/publish | POST | articles | 10 |
pg = > web.page title="mw"
app = > web.app page=pg
app = > app.configure cors=cors security=sec compress=True body_limit=1048576 json=api
mw = middleware
cobj = cors origins = allow_origins o0 = 1
o0== "https://a.example"
print text=cors-origin-ok
print text=cors-origin-fail
m1== "POST"
print text=cors-method-ok
print text=cors-method-fail
expose = expose_headers e0 = 1
e0== "X-Total"
print text=cors-expose-ok
print text=cors-expose-fail
cred = credentials
cred
print text=cors-cred-ok
print text=cors-cred-fail
secmap = security frame = X-Frame-Options
frame== "DENY"
print text=security-frame-ok
print text=security-frame-fail
csp = Content-Security-Policy
csp== "default-src 'self'"
print text=security-csp-ok
print text=security-csp-fail
comp = compress
comp
print text=compress-ok
print text=compress-fail
bl = body_limit
bl== 1048576
print text=body-limit-ok
print text=body-limit-fail
jmap = json_routes posts = api/posts pok = method
pok== "GET"
print text=json-get-ok
print text=json-get-fail
ptable = table
ptable== "articles"
print text=json-table-ok
print text=json-table-fail
porder = order
porder== "-created_at"
print text=json-order-ok
print text=json-order-fail
plimit = limit
plimit== 20
print text=json-limit-ok
print text=json-limit-fail
pub = api/publish pmethod = method
pmethod== "POST"
print text=json-post-ok
print text=json-post-fail