|
@@ -58,13 +58,14 @@ app.use("/api", apiRoutes);
|
|
|
|
|
|
|
|
// 1. 服务 Angular 应用的静态文件
|
|
// 1. 服务 Angular 应用的静态文件
|
|
|
// 这会处理所有构建产物,例如 .js, .css, .ico 文件
|
|
// 这会处理所有构建产物,例如 .js, .css, .ico 文件
|
|
|
-const angularAppPath = path.join(__dirname, "..", "public", "app");
|
|
|
|
|
|
|
+const angularAppPath = path.join(__dirname, "..", "public");
|
|
|
app.use(express.static(angularAppPath));
|
|
app.use(express.static(angularAppPath));
|
|
|
|
|
|
|
|
// 2. 对于所有未被前面路由(如 /api 或静态文件)处理的请求,
|
|
// 2. 对于所有未被前面路由(如 /api 或静态文件)处理的请求,
|
|
|
-// 都返回 Angular 应用的 index.html 文件
|
|
|
|
|
-app.get("*", (req: Request, res: Response) => {
|
|
|
|
|
- res.sendFile(path.join(angularAppPath, "index.html"));
|
|
|
|
|
|
|
+// 都返回 Angular 应用的 index.html 文件。
|
|
|
|
|
+// app.use() 是一个更通用的中间件,可以作为通配符来处理所有未匹配的请求。
|
|
|
|
|
+app.use((req: Request, res: Response) => {
|
|
|
|
|
+ res.sendFile(path.join(angularAppPath, "app", "index.html"));
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Start the server
|
|
// Start the server
|