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

Function createServer

apps/cli/src/http/server.ts:20–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18const JSON_BODY_LIMIT = 50 * 1024 * 1024 // 50MB
19
20export function createServer(): FastifyInstance {
21 const server = Fastify({
22 logger: false,
23 bodyLimit: JSON_BODY_LIMIT,
24 })
25
26 server.addHook('onRequest', authHook)
27
28 server.setErrorHandler((error: FastifyError, request, reply) => {
29 const apiError = apiErrorFromUnknown(error)
30 if (apiError) {
31 reply.code(apiError.statusCode).send(errorResponse(apiError))
32 return
33 }
34
35 if (error.statusCode === 413) {
36 const bodyErr = new ApiError(ApiErrorCode.BODY_TOO_LARGE, 'Request body exceeds 50MB limit')
37 reply.code(413).send(errorResponse(bodyErr))
38 return
39 }
40
41 const statusCode = (error as any).statusCode
42 if (statusCode && statusCode >= 400 && statusCode < 600) {
43 reply.code(statusCode).send({ success: false, error: { code: 'CLIENT_ERROR', message: error.message } })
44 return
45 }
46
47 appLogger.error('http', `${request.method} ${request.url} -> 500`, error)
48 const err = serverError(error.message)
49 reply.code(err.statusCode).send(errorResponse(err))
50 })
51
52 return server
53}

Callers 2

startHttpServerFunction · 0.90
server.test.tsFile · 0.90

Calls 4

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

Tested by

no test coverage detected