MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / createServer

Function createServer

apps/desktop/main/api/server.ts:12–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10const JSON_BODY_LIMIT = 50 * 1024 * 1024 // 50MB
11
12export function createServer(): FastifyInstance {
13 const server = Fastify({
14 logger: false,
15 bodyLimit: JSON_BODY_LIMIT,
16 })
17
18 server.addHook('onRequest', authHook)
19
20 server.setErrorHandler((error: FastifyError, _request, reply) => {
21 if (error instanceof ApiError) {
22 reply.code(error.statusCode).send(errorResponse(error))
23 return
24 }
25
26 const apiError = apiErrorFromUnknown(error)
27 if (apiError) {
28 reply.code(apiError.statusCode).send(errorResponse(apiError))
29 return
30 }
31
32 if (error.statusCode === 413) {
33 const bodyErr = new ApiError(ApiErrorCode.BODY_TOO_LARGE, 'Request body exceeds 50MB limit')
34 reply.code(413).send(errorResponse(bodyErr))
35 return
36 }
37
38 apiLogger.error('Unhandled error', error)
39 const err = serverError(error.message)
40 reply.code(err.statusCode).send(errorResponse(err))
41 })
42
43 return server
44}

Callers 1

startFunction · 0.90

Calls 4

errorResponseFunction · 0.90
apiErrorFromUnknownFunction · 0.90
serverErrorFunction · 0.90
errorMethod · 0.65

Tested by

no test coverage detected