feat: 搭建前后端可执行程序示例
This commit is contained in:
25
src/server/server.ts
Normal file
25
src/server/server.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { RuntimeMode } from "../shared/api";
|
||||
import { createFetchHandler, type StaticAssets } from "./app";
|
||||
import { readRuntimeConfig, type RuntimeConfig } from "./config";
|
||||
|
||||
export interface StartServerOptions {
|
||||
config?: RuntimeConfig;
|
||||
mode: RuntimeMode;
|
||||
staticAssets?: StaticAssets;
|
||||
}
|
||||
|
||||
export function startServer(options: StartServerOptions) {
|
||||
const config = options.config ?? readRuntimeConfig();
|
||||
const server = Bun.serve({
|
||||
hostname: config.host,
|
||||
port: config.port,
|
||||
fetch: createFetchHandler({
|
||||
mode: options.mode,
|
||||
staticAssets: options.staticAssets,
|
||||
}),
|
||||
});
|
||||
|
||||
console.log(`Gateway Checker listening on ${server.url}`);
|
||||
|
||||
return server;
|
||||
}
|
||||
Reference in New Issue
Block a user