Files
new-api-key-usage/apps/server/src/index.ts
T
skycurtain ea4efbe1d7 feat(deploy): 一条命令链部署——双单文件 + Caddy + DATABASE_URL 单源
多阶段镜像编出 server/engine 单文件与前端静态;compose 起 pg/server/engine/caddy;
启动时自动迁移;仅用 DATABASE_URL,postgres 建库参数由 entrypoint 拆解。
2026-10-10 16:46:54 +08:00

36 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { fileURLToPath } from "node:url";
import { createApp } from "./app.ts";
import { loadEnv } from "./env.ts";
import { createDb, runMigrations } from "@new-api-key-usage/db";
import { appLogger, setupLogging } from "@new-api-key-usage/core";
const env = loadEnv(process.env);
setupLogging(env.LOG_LEVEL);
const db = createDb(env.DATABASE_URL);
const migrationsFolder =
process.env.MIGRATIONS_FOLDER ??
fileURLToPath(new URL("../../../packages/db/drizzle", import.meta.url));
await runMigrations(db, migrationsFolder);
appLogger("server").info("数据库迁移已就绪");
const app = createApp({
db,
skKeyEncryptionSecret: env.SK_KEY_ENCRYPTION_SECRET,
newapiBase: env.NEWAPI_BASE,
cookieSecure: env.COOKIE_SECURE,
adminInitUsername: env.ADMIN_INIT_USERNAME,
adminInitPassword: env.ADMIN_INIT_PASSWORD,
});
appLogger("server").info(
`服务已启动,端口 ${env.PORT}(cookie_secure=${env.COOKIE_SECURE},日志级别=${env.LOG_LEVEL})`,
);
export default {
port: env.PORT,
fetch: app.fetch,
};