-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.ts
More file actions
27 lines (22 loc) · 696 Bytes
/
plugin.ts
File metadata and controls
27 lines (22 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/// <reference path="./global.d.ts" />
import Ajv from "ajv";
import type { FastifyInstance, FastifyPluginOptions } from "fastify";
import { counterService } from "./services/counter.service";
export default async function (
app: FastifyInstance,
opts: FastifyPluginOptions,
) {
app.log.info("plugin loaded");
app.log.info(`plugin options: ${JSON.stringify(opts)}`);
// Setup validator
const ajv = new Ajv({
removeAdditional: "all",
useDefaults: true,
coerceTypes: "array",
});
app.setValidatorCompiler(({ schema }) => ajv.compile(schema));
// Simpler counter service
counterService(app);
// Health check
app.get("/health/check", () => ({ ok: true }));
}