2022-09-05 21:12:35 +09:00
|
|
|
import fastify, { type FastifyInstance } from "fastify";
|
|
|
|
import defaultConfig, { type Config } from "./config";
|
|
|
|
import routes from "./routes/index";
|
|
|
|
|
|
|
|
declare module "fastify" {
|
|
|
|
interface FastifyInstance {
|
|
|
|
config: Config;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function App(config: Config = defaultConfig()): FastifyInstance {
|
2022-09-07 05:51:57 +09:00
|
|
|
const app = fastify({ logger: { stream: process.stderr, level: "warn" } });
|
2022-09-05 21:12:35 +09:00
|
|
|
app.decorate("config", config).register(routes);
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function start(app: FastifyInstance): Promise<string> {
|
|
|
|
await app.ready();
|
|
|
|
const address = await app.listen({ host: "::", port: app.config.port });
|
|
|
|
return address;
|
|
|
|
}
|