wildpig 1.4.1 → 1.5.0

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/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "wildpig",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "author": "eriktse",
5
- "main": "index.ts",
6
5
  "type": "module",
7
6
  "bin": {
8
7
  "wildpig": "./bin/cli.ts"
package/scripts/build.ts CHANGED
@@ -6,14 +6,14 @@ const prebuild = async () => {
6
6
  const promises = [];
7
7
  // 先编译客户端代码
8
8
  promises.push(viteBuild({
9
- configFile: path.resolve(__dirname, "../vite.config.ts"),
9
+ configFile: path.resolve(__dirname, "../../../vite.config.ts"),
10
10
  build: {
11
11
  outDir: "./dist/client",
12
12
  },
13
13
  }));
14
14
  // 编译服务端入口文件
15
15
  promises.push(viteBuild({
16
- configFile: path.resolve(__dirname, "../vite.config.ts"),
16
+ configFile: path.resolve(__dirname, "../../../vite.config.ts"),
17
17
 
18
18
  build: {
19
19
  rollupOptions:{
@@ -6,9 +6,9 @@ import fs from "node:fs";
6
6
  const __dirname = import.meta.dirname;
7
7
 
8
8
  // 用户代码
9
- import pageRoutes from "@/router/routes";
10
9
  import path from "node:path";
11
10
  import chalk from "chalk";
11
+ import { WildPigRouteObject } from "router/types";
12
12
 
13
13
  const env = process.env;
14
14
  const port = env.PORT || 3000;
@@ -40,6 +40,7 @@ const viteHandler = (apiModules: any) => async (request: Request) => {
40
40
  return response.clone();
41
41
  }
42
42
 
43
+ const pageRoutes = (await viteServer.ssrLoadModule("@/router/routes.ts"!)).default as WildPigRouteObject[];
43
44
  const matches = matchRoutes(pageRoutes, url.pathname);
44
45
  if(!matches)return new Response("404 Not Found", { status: 404 });
45
46
 
@@ -4,8 +4,9 @@ import { matchRoutes } from "react-router";
4
4
  import path from "node:path";
5
5
 
6
6
  // 用户代码
7
- import pageRoutes from "#/src/router/routes";
7
+ const pageRoutes = (await import("@/router/routes"!)).default as WildPigRouteObject[];
8
8
  import chalk from "chalk";
9
+ import { WildPigRouteObject } from "router/types";
9
10
 
10
11
  const env = process.env;
11
12
  const port = env.PORT || 3000;
@@ -46,8 +47,7 @@ export const startServer = async () => {
46
47
  "/*": async (request: Request) => {
47
48
  // 判断pathname是否匹配pageRoutes
48
49
  const url = new URL(request.url);
49
- const matches = matchRoutes(pageRoutes, url.pathname);
50
- if(!matches){
50
+ if(url.pathname.includes(".") || url.pathname.startsWith("/@") || url.pathname.startsWith("/assets")){
51
51
  const filepath = "./client" + url.pathname;
52
52
  // 检查文件是否存在
53
53
  if(fs.existsSync(filepath) && fs.statSync(filepath).isFile()){
@@ -58,6 +58,9 @@ export const startServer = async () => {
58
58
  }
59
59
 
60
60
  // 请求服务端数据
61
+ const matches = matchRoutes(pageRoutes, url.pathname);
62
+ if(!matches)return new Response("Not Found", {status: 404});
63
+
61
64
  const matchRoute = matches.at(-1)!;
62
65
  let serverDataApi = matchRoute.route.serverDataApi;
63
66
  const getServerData = async () => {