File tree Expand file tree Collapse file tree
functions/api/prox/forward Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33interface Env {
44 API_URL : string
55 BLOG_URL : string
6+ PROX_URL : string
67}
Original file line number Diff line number Diff line change 1+ export const onRequest = async ( context : EventContext < Env , 'path' , unknown > ) => {
2+ const url = new URL ( context . request . url )
3+ const pathSegments = context . params . path as string [ ] | undefined
4+ const targetPath = pathSegments ?. join ( '/' ) || ''
5+ const targetUrl = `${ context . env . PROX_URL . replace ( / \/ $ / , '' ) } /${ targetPath } ${ url . search } `
6+
7+ const headers = new Headers ( context . request . headers )
8+ headers . delete ( 'host' )
9+
10+ try {
11+ const response = await fetch ( targetUrl , {
12+ method : context . request . method ,
13+ headers,
14+ body : context . request . body
15+ } )
16+
17+ return new Response ( response . body , {
18+ status : response . status ,
19+ statusText : response . statusText ,
20+ headers : response . headers
21+ } )
22+ } catch {
23+ return new Response ( 'Fetch Error' , {
24+ status : 502 ,
25+ headers : { 'Content-Type' : 'text/plain; charset=utf-8' }
26+ } )
27+ }
28+ }
Original file line number Diff line number Diff line change 1212 <code >/api/host/search?[string]domain=wikipedia.org</code >
1313 </li >
1414 <li ><a href =" /api/host/check" >测试内置规则</a > <code >/api/host/check</code ></li >
15+ <li >
16+ <a href =" /api/prox/forward/" >透传代理请求</a >
17+ <code >/api/prox/forward/[string]?[any]</code >
18+ </li >
1519 <li >
1620 <a href =" /files/host/Cealing-Host.json" >订阅内置规则</a >
17- <code >/files/host/[string]path =Cealing-Host.json</code >
21+ <code >/files/host/[string]=Cealing-Host.json</code >
1822 </li >
1923 <li >
2024 <a href =" /files/gallery/SpaceTime-Server-0.2.0.mp4" >下载宣传物料</a >
21- <code >/files/gallery/[string]path =SpaceTime-Server-0.2.0.mp4</code >
25+ <code >/files/gallery/[string]=SpaceTime-Server-0.2.0.mp4</code >
2226 </li >
2327 <li >
2428 <a href =" /files/blog/atom.xml" >订阅博客更新</a >
25- <code >/files/blog/[string]path =atom.xml</code >
29+ <code >/files/blog/[string]=atom.xml</code >
2630 </li >
2731 </ul >
28- <p >0.3.6 by Space Time</p >
32+ <p >0.3.7 by Space Time</p >
2933 </main >
3034</template >
3135
Original file line number Diff line number Diff line change 11<Project Sdk =" Microsoft.NET.Sdk.Web" >
22
33 <PropertyGroup >
4- <InformationalVersion >0.3.6 </InformationalVersion >
4+ <InformationalVersion >0.3.7 </InformationalVersion >
55 <TargetFramework >net9.0</TargetFramework >
66 <RootNamespace >SpaceTime_Server</RootNamespace >
77 <ImplicitUsings >disable</ImplicitUsings >
You can’t perform that action at this time.
0 commit comments