MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / pluginHandler

Function pluginHandler

packages/server/src/adapter/fastify/plugin.ts:28–56  ·  view source on GitHub ↗
(fastify, options, done)

Source from the content-addressed store, hash-verified

26 * Fastify plugin for handling CRUD requests.
27 */
28const pluginHandler: FastifyPluginCallback<FastifyPluginOptions<SchemaDef>> = (fastify, options, done) => {
29 const prefix = options.prefix ?? '';
30
31 fastify.all(`${prefix}/*`, async (request, reply) => {
32 const client = await options.getClient(request, reply);
33 if (!client) {
34 reply.status(500).send({ message: 'unable to get ZenStackClient from request context' });
35 return reply;
36 }
37
38 try {
39 const response = await options.apiHandler.handleRequest({
40 method: request.method,
41 path: (request.params as any)['*'],
42 query: request.query as Record<string, string | string[]>,
43 requestBody: request.body,
44 client,
45 });
46 reply.status(response.status).send(response.body);
47 } catch (err) {
48 logInternalError(options.apiHandler.log, err);
49 reply.status(500).send({ message: `An internal server error occurred` });
50 }
51
52 return reply;
53 });
54
55 done();
56};
57
58const plugin = fp(pluginHandler);
59

Callers

nothing calls this directly

Calls 2

logInternalErrorFunction · 0.90
handleRequestMethod · 0.65

Tested by

no test coverage detected