Skip to content

Commit 90ea795

Browse files
committed
0.3.7 更新
1 parent 64dcc16 commit 90ea795

4 files changed

Lines changed: 38 additions & 5 deletions

File tree

SpaceTime-Client/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
interface Env {
44
API_URL: string
55
BLOG_URL: string
6+
PROX_URL: string
67
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

SpaceTime-Client/src/App.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,24 @@
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

SpaceTime-Server/SpaceTime-Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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>

0 commit comments

Comments
 (0)