Skip to content

Commit c7d7b24

Browse files
authored
ci: 增加eo部署所需的文件和命令 (#49)
* fix: 增加eo依赖缺失的文件 * ci: 修改edgeone部署相关配置 * ci: 增加eo构建指令 * fix: 适配eo ./public 输出路径
1 parent 7c77336 commit c7d7b24

File tree

3 files changed

+144
-1
lines changed

3 files changed

+144
-1
lines changed

edgeone.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"rewrites": [
3+
{
4+
"source": "/",
5+
"destination": "/index.html"
6+
}
7+
]
8+
}

functions/index.ts

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,139 @@
1-
import {app} from '../src'
1+
import { app } from '../src'
2+
import { Context } from 'hono'
23

4+
const notFound = async (c: Context) => {
5+
return c.html(
6+
`
7+
<!DOCTYPE html>
8+
<html>
9+
<head>
10+
<meta charset="UTF-8">
11+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
12+
<title>404 - Page Not Found</title>
13+
<style>
14+
body {
15+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
16+
line-height: 1.6;
17+
margin: 0;
18+
padding: 20px;
19+
background-color: #f5f5f5;
20+
text-align: center;
21+
}
22+
.container {
23+
max-width: 600px;
24+
margin: 100px auto;
25+
background: white;
26+
padding: 40px;
27+
border-radius: 8px;
28+
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
29+
}
30+
h1 {
31+
color: #e74c3c;
32+
font-size: 72px;
33+
margin: 0;
34+
}
35+
h2 {
36+
color: #333;
37+
margin: 20px 0;
38+
}
39+
</style>
40+
</head>
41+
<body>
42+
<div class="container">
43+
<h1>404</h1>
44+
<h2>Page Not Found</h2>
45+
<p>The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.</p>
46+
<p><a href="/">← Go back to home</a></p>
47+
</div>
48+
</body>
49+
</html>
50+
`,
51+
404
52+
);
53+
};
54+
55+
// Fallback to static directory
56+
app.notFound(async (c) => {
57+
const url = new URL(c.req.url);
58+
59+
if (url.pathname === '/') {
60+
url.pathname = '/index.html';
61+
}
62+
63+
try {
64+
const res = await fetch(url.toString(), {
65+
headers: c.req.header()
66+
});
67+
68+
if (res.ok) {
69+
const contentType = res.headers.get('Content-Type')!;
70+
const body = await res.arrayBuffer();
71+
72+
return new Response(body, {
73+
status: res.status,
74+
headers: {
75+
'Content-Type': contentType,
76+
'Cache-Control': 'public, max-age=3600',
77+
},
78+
});
79+
}
80+
} catch (error) {
81+
return notFound(c);
82+
}
83+
return notFound(c);
84+
});
85+
86+
app.onError((err, c) => {
87+
return c.html(
88+
`
89+
<!DOCTYPE html>
90+
<html>
91+
<head>
92+
<meta charset="UTF-8">
93+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
94+
<title>500 - Internal Server Error</title>
95+
<style>
96+
body {
97+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
98+
line-height: 1.6;
99+
margin: 0;
100+
padding: 20px;
101+
background-color: #f5f5f5;
102+
text-align: center;
103+
}
104+
.container {
105+
max-width: 600px;
106+
margin: 100px auto;
107+
background: white;
108+
padding: 40px;
109+
border-radius: 8px;
110+
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
111+
}
112+
h1 {
113+
color: #e74c3c;
114+
font-size: 72px;
115+
margin: 0;
116+
}
117+
h2 {
118+
color: #333;
119+
margin: 20px 0;
120+
}
121+
</style>
122+
</head>
123+
<body>
124+
<div class="container">
125+
<h1>500</h1>
126+
<h2>Internal Server Error</h2>
127+
<p>Something went wrong on our server. Please try again later.</p>
128+
<p>Error: ${err.message}</p>
129+
<p><a href="/">← Go back to home</a></p>
130+
</div>
131+
</body>
132+
</html>
133+
`,
134+
500
135+
);
136+
});
3137
export function onRequest(context: {
4138
request: Request;
5139
params: Record<string, string>;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"scripts": {
44
"dev-js": "tsx watch src/basic.ts",
55
"build-js": "webpack --mode production",
6+
"build-eo": "edgeone pages build",
67
"dev-cf": "wrangler dev",
78
"deploy-cf": "wrangler deploy --minify",
89
"dev-eo": "edgeone pages dev",

0 commit comments

Comments
 (0)