|
@@ -6,19 +6,30 @@ import { pipeline } from 'node:stream/promises';
|
|
|
import { serve } from '@hono/node-server';
|
|
import { serve } from '@hono/node-server';
|
|
|
import { Hono } from 'hono';
|
|
import { Hono } from 'hono';
|
|
|
import { createServer as createNodeServer } from 'node:http';
|
|
import { createServer as createNodeServer } from 'node:http';
|
|
|
|
|
+import process from 'node:process';
|
|
|
|
|
|
|
|
// 创建 Hono 应用
|
|
// 创建 Hono 应用
|
|
|
const app = new Hono();
|
|
const app = new Hono();
|
|
|
|
|
|
|
|
// Constants
|
|
// Constants
|
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
|
-const port = process.env.PORT || 5173;
|
|
|
|
|
|
|
+const port = process.env.PORT || 8080;
|
|
|
const base = process.env.BASE || '/';
|
|
const base = process.env.BASE || '/';
|
|
|
const ABORT_DELAY = 10000;
|
|
const ABORT_DELAY = 10000;
|
|
|
|
|
|
|
|
// 解析基础路径为 URL 对象,方便后续处理
|
|
// 解析基础路径为 URL 对象,方便后续处理
|
|
|
const baseUrl = new URL(base, `http://localhost:${port}`);
|
|
const baseUrl = new URL(base, `http://localhost:${port}`);
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+// 使用 Hono 的 serve 启动服务器
|
|
|
|
|
+const parentServer = serve({
|
|
|
|
|
+ fetch: app.fetch,
|
|
|
|
|
+ createServer: createNodeServer,
|
|
|
|
|
+ port: port,
|
|
|
|
|
+}, () => {
|
|
|
|
|
+ console.log(`Server started at http://localhost:${port}`);
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
// Cached production assets
|
|
// Cached production assets
|
|
|
let templateHtml = '';
|
|
let templateHtml = '';
|
|
|
if (isProduction) {
|
|
if (isProduction) {
|
|
@@ -42,7 +53,22 @@ let vite;
|
|
|
if (!isProduction) {
|
|
if (!isProduction) {
|
|
|
const { createServer } = await import('vite');
|
|
const { createServer } = await import('vite');
|
|
|
vite = await createServer({
|
|
vite = await createServer({
|
|
|
- server: { middlewareMode: true },
|
|
|
|
|
|
|
+ server: { middlewareMode: {
|
|
|
|
|
+ server: parentServer
|
|
|
|
|
+ },
|
|
|
|
|
+ hmr: {
|
|
|
|
|
+ port: 8081,
|
|
|
|
|
+ clientPort: 443, // 或其他可用端口
|
|
|
|
|
+ path: 'vite-hmr'
|
|
|
|
|
+ },
|
|
|
|
|
+ proxy: {
|
|
|
|
|
+ '/vite-hmr': {
|
|
|
|
|
+ target: 'ws://localhost:8081',
|
|
|
|
|
+ // Proxying WebSocket
|
|
|
|
|
+ ws: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
appType: 'custom',
|
|
appType: 'custom',
|
|
|
base,
|
|
base,
|
|
|
});
|
|
});
|
|
@@ -181,12 +207,3 @@ app.use(async (c) => {
|
|
|
return c.text(e.stack, 500);
|
|
return c.text(e.stack, 500);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
-// 使用 Hono 的 serve 启动服务器
|
|
|
|
|
-serve({
|
|
|
|
|
- fetch: app.fetch,
|
|
|
|
|
- createServer: createNodeServer,
|
|
|
|
|
- port: port,
|
|
|
|
|
-}, () => {
|
|
|
|
|
- console.log(`Server started at http://localhost:${port}`);
|
|
|
|
|
-});
|
|
|