@opengis/fastify-table
Version:
core-plugins
36 lines (35 loc) • 1.1 kB
JavaScript
import Fastify from "fastify";
import config from "./config.js";
import appService from "./index.js";
import { pgClients } from "./utils.js";
const { prefix = "/api" } = config;
let app;
export async function setup() {
console.log("Global setup");
app = await build();
console.log("Global setup finish");
}
// ? close clients via vitest.config.js settings deploy, for npx vitest run
export async function teardown() {
console.log("Global teardown: closing all clients");
if (app) {
app.close();
console.log("Global teardown: app closed");
}
console.log("Global teardown: all clients closed");
process.exit(0);
}
export async function build() {
if (!app) {
app = Fastify({ logger: false });
app.register(appService, config);
app.addHook("onRequest", async (req) => {
req.user = req.user || { uid: "1", user_type: "admin" };
});
await app.ready(); // ? ensure plugins registered, can not add fastify hooks after app is ready
}
return app;
}
export {
// teardown,
prefix, config, pgClients, };