wildpig 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +3 -3
- package/public/index.html +6 -1
- package/scripts/WildPig.ts +18 -8
- package/scripts/prepareRoutes.ts +1 -1
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wildpig",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"author": "eriktse",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"dependencies": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"react": "^19.2.3",
|
|
12
12
|
"react-dom": "^19.2.3"
|
|
13
13
|
},
|
|
14
|
-
"description": "A strong and fast fullstack framework base Bun.",
|
|
14
|
+
"description": "A strong and fast fullstack framework base on Bun, react, react-router, typescript, tailwindcss.",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"fullstack",
|
|
17
17
|
"web",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"scripts": {
|
|
22
|
-
"dev": "export NODE_ENV=development && bun run test.ts",
|
|
22
|
+
"dev": "export NODE_ENV=development && bun run --hot test.ts",
|
|
23
23
|
"prebuild": "bun run scripts/run-prebuild.ts",
|
|
24
24
|
"build": "export NODE_ENV=production && bun run prebuild && bun build --compile ./test.ts --outfile dist/wildpig",
|
|
25
25
|
"build-linux-musl": "export NODE_ENV=production && bun build --compile --target=bun-linux-x64-musl ./test.ts --outfile dist/wildpig",
|
package/public/index.html
CHANGED
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<
|
|
6
|
+
<meta name="wildpig-environment" content="production">
|
|
7
|
+
|
|
7
8
|
<title>{{TITLE}}</title>
|
|
9
|
+
<meta name="description" content="{{DESCRIPTION}}">
|
|
10
|
+
<meta name="keywords" content="{{KEYWORDS}}">
|
|
11
|
+
|
|
12
|
+
<script src="/render.js" type="module"></script>
|
|
8
13
|
</head>
|
|
9
14
|
<body>
|
|
10
15
|
<div id="root"></div>
|
package/scripts/WildPig.ts
CHANGED
|
@@ -7,6 +7,8 @@ import devIndexHtml from "#/public/devIndex.html"
|
|
|
7
7
|
const env = process.env;
|
|
8
8
|
const isDev = env.NODE_ENV === "development";
|
|
9
9
|
|
|
10
|
+
console.log(metaRoutes);
|
|
11
|
+
|
|
10
12
|
|
|
11
13
|
export const startServer = () => {
|
|
12
14
|
Bun.serve({
|
|
@@ -27,17 +29,25 @@ export const startServer = () => {
|
|
|
27
29
|
"Cache-Control": isDev ? "no-cache" : "public, max-age=31536000, immutable"
|
|
28
30
|
}
|
|
29
31
|
}),
|
|
30
|
-
"/*":
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const pathname = "/_WILDPIG_META_API" + url.split("?")[0];
|
|
34
|
-
let
|
|
32
|
+
"/*":
|
|
33
|
+
isDev ? devIndexHtml :
|
|
34
|
+
async (request: Request) => {
|
|
35
|
+
const pathname = "/_WILDPIG_META_API/" + (request.url.split("/")[3].split("?")[0] || "");
|
|
36
|
+
let resHtml = htmlString;
|
|
35
37
|
|
|
36
38
|
if(pathname in metaRoutes){
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
try{
|
|
40
|
+
const metaResponse = await metaRoutes[pathname](request);
|
|
41
|
+
const meta = await metaResponse.json();
|
|
42
|
+
if(meta.title)resHtml = resHtml.replace("{{TITLE}}", meta.title);
|
|
43
|
+
if(meta.description)resHtml = resHtml.replace("{{DESCRIPTION}}", meta.description);
|
|
44
|
+
if(meta.keywords)resHtml = resHtml.replace("{{KEYWORDS}}", meta.keywords.join(", "));
|
|
45
|
+
}catch(e){
|
|
46
|
+
console.error("获取meta信息失败,请检查是否设置了meta信息", e);
|
|
47
|
+
}
|
|
39
48
|
}
|
|
40
|
-
|
|
49
|
+
|
|
50
|
+
return new Response(resHtml, {
|
|
41
51
|
headers: {
|
|
42
52
|
"content-type": "text/html; charset=utf-8",
|
|
43
53
|
"Access-Control-Allow-Origin": "*",
|
package/scripts/prepareRoutes.ts
CHANGED
|
@@ -6,7 +6,7 @@ const isDev = process.env.NODE_ENV === "development";
|
|
|
6
6
|
|
|
7
7
|
// 准备服务端路由表
|
|
8
8
|
let routes = {};
|
|
9
|
-
let metaRoutes: Record<string, () => Promise<Response>> = {};
|
|
9
|
+
let metaRoutes: Record<string, (req: Request) => Promise<Response>> = {};
|
|
10
10
|
if(isDev){
|
|
11
11
|
// 引入,用于监听
|
|
12
12
|
setTimeout(() => import("@/App").catch(() => {}), 1000);
|