接口参考
可以使用以下方法配置页面功能。
方法
onRequests
(关于请求
onRequest(contextEventContext)
Response | Promise<Response>
- 无论请求方法如何,所有请求都将调用该函数。
onRequestGet(contextEventContext)
Response | Promise<Response>
- 所有
GET
请求都将调用该函数。
- 所有
onRequestPost(contextEventContext)
Response | Promise<Response>
- 所有
POST
请求都将调用该函数。
- 所有
onRequestPatch(contextEventContext)
Response | Promise<Response>
- 所有
PATCH
请求都将调用该函数。
- 所有
onRequestPut(contextEventContext)
Response | Promise<Response>
- 所有
PUT
请求都将调用该函数。
- 所有
onRequestDelete(contextEventContext)
Response | Promise<Response>
- 所有
DELETE
请求都将调用该函数。
- 所有
onRequestHead(contextEventContext)
Response | Promise<Response>
- 所有
HEAD
请求都将调用该函数。
- 所有
onRequestOptions(contextEventContext)
Response | Promise<Response>
- 所有
OPTIONS
请求都将调用该函数。
- 所有
env.ASSETS.fetch()
通过 env.ASSETS.fetch()
函数,你可以从 Pages 项目中获取静态资产。
你可以向env.ASSETS.fetch()
函数传递请求对象、URL 字符串或 URL 对象。URL 必须指向漂亮路径,而不是直接指向资产。例如,如果你的路径是 /users/index.html
,你将请求 /users/
,而不是 /users/index.html
。此方法调用将运行头和重定向规则,修改返回的响应。
类型
EventContext
事件上下文
以下是在 onRequest
方法中传递的 context
对象的属性:
-
request
Request
这是传入的 请求。
-
functionPath
string
这是请求的路径。
-
waitUntil(promisePromise<any>)
void
更多信息请参阅
waitUntil
文档。 -
passThroughOnException()
void
更多信息请参阅
passThroughOnException
文档。请注意,这将无法在 advanced mode project 上运行。 -
next(input?Request | string, init?RequestInit)
Promise<Response>
将请求传递到下一个功能,如果没有其他功能,则传递到资产服务器。
-
env
EnvWithFetch
-
params
Params<P>
保存 dynamic routing 中的值。
在下面的示例中,动态路径为
/users/[user].js
。当你访问/users/nevi
上的网站时,params
对象将显示如下内容:这样就可以从路径中获取动态值:
Which would return
"Hello nevi"
. -
data
Data
EnvWithFetch
.
保存函数的环境变量、秘密和绑定。它还保存了 ASSETS
绑定,这样就可以回退到资产服务行为。