@3sixty/api-server-fastify 0.0.0-stage → 0.20.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +24 -2
- package/dist/es/fastifySocketIo.js +16 -0
- package/dist/es/fastifySocketIo.js.map +1 -0
- package/dist/es/fastifyWebServer.js +364 -0
- package/dist/es/fastifyWebServer.js.map +1 -0
- package/dist/es/index.js +6 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IFastifyWebServerConfig.js +2 -0
- package/dist/es/models/IFastifyWebServerConfig.js.map +1 -0
- package/dist/es/models/IFastifyWebServerConstructorOptions.js +2 -0
- package/dist/es/models/IFastifyWebServerConstructorOptions.js.map +1 -0
- package/dist/types/fastifySocketIo.d.ts +8 -0
- package/dist/types/fastifyWebServer.d.ts +74 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/models/IFastifyWebServerConfig.d.ts +22 -0
- package/dist/types/models/IFastifyWebServerConstructorOptions.d.ts +19 -0
- package/docs/changelog.md +21 -0
- package/docs/examples.md +37 -0
- package/docs/reference/classes/FastifyWebServer.md +834 -0
- package/docs/reference/index.md +10 -0
- package/docs/reference/interfaces/IFastifyWebServerConfig.md +33 -0
- package/docs/reference/interfaces/IFastifyWebServerConstructorOptions.md +27 -0
- package/locales/.validate-ignore +3 -0
- package/locales/en.json +14 -0
- package/package.json +56 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastifyWebServer.js","sources":["../../src/fastifyWebServer.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,mCAAmC;AACnC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EACN,aAAa,EACb,eAAe,EAWf,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,YAAY,EAAe,EAAE,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEtF,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,EAAE;SACnB,CAAC;QACF,MAAM,YAAY,GAAkB,EAAE,CAAC;QACvC,MAAM,UAAU,GAAgB,EAAE,CAAC;QACnC,MAAM,cAAc,GAAG,EAAE,CAAC;QAE1B,OAAO,mBAAmB,CAAC,KAAK,EAAE,GAAG,CAAC;QACtC,OAAO,mBAAmB,CAAC,KAAK,EAAE,SAAS,CAAC;QAE5C,MAAM,IAAI,CAAC,mBAAmB,CAC7B,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,UAAU,EACV,cAAc,EACd,SAAS,EACT,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;YACzB,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC9B,CAAC,CACD,CAAC;IACH,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,QAAQ,CAAC,OAA2B;QACjD,MAAM,WAAW,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAErD,MAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE;YACzC,MAAM,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE;gBAC5B,QAAQ,CACP,IAAI,EACJ,WAAW,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAgB,CAAC,CACrF,CAAC;YACH,CAAC;YACD,OAAO,EAAE,WAAW,CAAC,OAAO;YAC5B,cAAc,EAAE,WAAW,CAAC,cAAc;YAC1C,cAAc,EAAE,WAAW,CAAC,cAAc;YAC1C,WAAW,EAAE,IAAI;SACjB,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// Copyright 2026 3Sixty Trade Ltd.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseServer } from \"@3sixty/api-core-server\";\nimport {\n\tHttpBodyLimit,\n\tHttpErrorHelper,\n\ttype IHttpRequest,\n\ttype IHttpRequestPathParams,\n\ttype IHttpRequestQuery,\n\ttype IHttpResponse,\n\ttype IRestRoute,\n\ttype IRestRouteProcessor,\n\ttype ISocketRoute,\n\ttype ISocketRouteProcessor,\n\ttype ISocketServerRequest,\n\ttype IWebServerOptions\n} from \"@3sixty/api-models\";\nimport type { IContextIds } from \"@3sixty/context\";\nimport { BaseError, GeneralError, type IError, Is, StringHelper } from \"@3sixty/core\";\n\nimport { HttpMethod, HttpStatusCode, type IHttpHeaders } from \"@3sixty/web\";\nimport FastifyCompress from \"@fastify/compress\";\nimport FastifyCors from \"@fastify/cors\";\nimport Fastify, {\n\ttype FastifyInstance,\n\ttype FastifyReply,\n\ttype FastifyRequest,\n\ttype FastifyServerOptions\n} from \"fastify\";\nimport type { Server, ServerOptions, Socket } from \"socket.io\";\nimport FastifySocketIO from \"./fastifySocketIo.js\";\nimport type { IFastifyWebServerConstructorOptions } from \"./models/IFastifyWebServerConstructorOptions.js\";\n\n/**\n * Implementation of the web server using Fastify.\n */\nexport class FastifyWebServer extends BaseServer<FastifyInstance> {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = \"FastifyWebServer\";\n\n\t/**\n\t * The Fastify instance.\n\t * @internal\n\t */\n\tprivate readonly _fastify: FastifyInstance;\n\n\t/**\n\t * The options for the socket server.\n\t * @internal\n\t */\n\tprivate readonly _socketConfig: Partial<ServerOptions>;\n\n\t/**\n\t * Create a new instance of FastifyWebServer.\n\t * @param options The options for the server.\n\t */\n\tconstructor(options?: IFastifyWebServerConstructorOptions) {\n\t\tsuper({\n\t\t\tloggingComponentType: options?.loggingComponentType,\n\t\t\tmimeTypeProcessors: options?.mimeTypeProcessors,\n\t\t\tincludeErrorStack: options?.config?.includeErrorStack\n\t\t});\n\n\t\tthis._fastify = Fastify({\n\t\t\trouterOptions: {\n\t\t\t\tmaxParamLength: 2000\n\t\t\t},\n\t\t\t...options?.config?.web\n\t\t\t// Need this cast for now as maxParamLength has moved in to routerOptions\n\t\t\t// but the TS defs has not been updated yet\n\t\t} as unknown as FastifyServerOptions);\n\t\tthis._socketConfig = {\n\t\t\tpath: \"/socket\",\n\t\t\t...options?.config?.socket\n\t\t};\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn FastifyWebServer.CLASS_NAME;\n\t}\n\n\t/**\n\t * Get the web server instance.\n\t * @returns The web server instance.\n\t */\n\tpublic getInstance(): FastifyInstance {\n\t\treturn this._fastify;\n\t}\n\n\t/**\n\t * Build the server.\n\t * @param restRouteProcessors The processors for incoming requests over REST.\n\t * @param restRoutes The REST routes.\n\t * @param socketRouteProcessors The processors for incoming requests over Sockets.\n\t * @param socketRoutes The socket routes.\n\t * @param options Options for building the server.\n\t * @returns A promise that resolves when the server is fully built and ready to start.\n\t */\n\tpublic async build(\n\t\trestRouteProcessors?: IRestRouteProcessor[],\n\t\trestRoutes?: IRestRoute[],\n\t\tsocketRouteProcessors?: ISocketRouteProcessor[],\n\t\tsocketRoutes?: ISocketRoute[],\n\t\toptions?: IWebServerOptions\n\t): Promise<void> {\n\t\tawait this.prepareBuild(\n\t\t\trestRouteProcessors,\n\t\t\trestRoutes,\n\t\t\tsocketRouteProcessors,\n\t\t\tsocketRoutes,\n\t\t\toptions\n\t\t);\n\n\t\tawait this._fastify.register(FastifyCompress);\n\n\t\tif (Is.arrayValue(socketRoutes)) {\n\t\t\tawait this._fastify.register(FastifySocketIO, this._socketConfig);\n\t\t}\n\n\t\tif (Is.arrayValue(this._mimeTypeProcessors)) {\n\t\t\tfor (const contentTypeHandler of this._mimeTypeProcessors) {\n\t\t\t\tthis._fastify.addContentTypeParser(\n\t\t\t\t\tcontentTypeHandler.getTypes(),\n\t\t\t\t\t{ parseAs: \"buffer\" },\n\t\t\t\t\t(request, body, done) => {\n\t\t\t\t\t\t// Fastify does not handle this method correctly if it is async\n\t\t\t\t\t\t// so we have to use the callback method\n\t\t\t\t\t\tcontentTypeHandler\n\t\t\t\t\t\t\t.handle(body as Buffer)\n\t\t\t\t\t\t\t// eslint-disable-next-line promise/prefer-await-to-then, promise/no-callback-in-promise\n\t\t\t\t\t\t\t.then(processed => done(null, processed))\n\t\t\t\t\t\t\t// eslint-disable-next-line promise/prefer-await-to-then, promise/no-callback-in-promise\n\t\t\t\t\t\t\t.catch(err => done(BaseError.fromError(err)));\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tawait this.initCors(options);\n\n\t\tthis._fastify.setNotFoundHandler({}, async (request, reply) =>\n\t\t\tthis.handleRequestRest(request, reply)\n\t\t);\n\n\t\tthis._fastify.setErrorHandler(\n\t\t\tasync (\n\t\t\t\terror: Error & {\n\t\t\t\t\tcode?: number | string;\n\t\t\t\t\tstatusCode?: number | string;\n\t\t\t\t},\n\t\t\t\trequest,\n\t\t\t\treply\n\t\t\t) => {\n\t\t\t\t// If code property is set this is a fastify error\n\t\t\t\t// otherwise it's from our framework\n\t\t\t\tlet httpStatusCode: HttpStatusCode;\n\t\t\t\tlet err: IError;\n\t\t\t\tif (Is.number(error.code) || Is.string(error.code)) {\n\t\t\t\t\terr = {\n\t\t\t\t\t\tsource: FastifyWebServer.CLASS_NAME,\n\t\t\t\t\t\tname: error.name,\n\t\t\t\t\t\tmessage: `${error.code}: ${error.message}`\n\t\t\t\t\t};\n\t\t\t\t\thttpStatusCode = (error.statusCode as HttpStatusCode) ?? HttpStatusCode.badRequest;\n\t\t\t\t} else {\n\t\t\t\t\tconst errorAndCode = HttpErrorHelper.processError(error);\n\t\t\t\t\terr = errorAndCode.error;\n\t\t\t\t\thttpStatusCode = errorAndCode.httpStatusCode;\n\t\t\t\t}\n\n\t\t\t\tawait this._logging?.log({\n\t\t\t\t\tlevel: \"error\",\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tsource: FastifyWebServer.CLASS_NAME,\n\t\t\t\t\tmessage: \"badRequest\",\n\t\t\t\t\terror: err\n\t\t\t\t});\n\n\t\t\t\treturn reply.status(httpStatusCode).send({\n\t\t\t\t\terror: err\n\t\t\t\t});\n\t\t\t}\n\t\t);\n\n\t\tawait this.addRoutesRest(restRouteProcessors, restRoutes);\n\t\tawait this.addRoutesSocket(socketRouteProcessors, socketRoutes);\n\t}\n\n\t/**\n\t * Start listening for connections on the transport.\n\t * @param host The host to bind to.\n\t * @param port The port to bind to.\n\t * @returns A promise that resolves when the transport is listening.\n\t */\n\tprotected async serverListen(host: string, port: number): Promise<void> {\n\t\tawait this._fastify.listen({ port, host });\n\t}\n\n\t/**\n\t * Close the transport and all of its connections.\n\t * @returns A promise that resolves when the transport has closed.\n\t */\n\tprotected async serverClose(): Promise<void> {\n\t\tawait this._fastify.close();\n\t}\n\n\t/**\n\t * Get the addresses the transport is bound to.\n\t * @returns The bound addresses.\n\t */\n\tprotected serverAddresses(): { address: string; family?: string; port: number }[] {\n\t\treturn this._fastify.addresses();\n\t}\n\n\t/**\n\t * Whether the transport is serving over TLS.\n\t * @returns True if the transport is secure.\n\t */\n\tprotected serverIsSecure(): boolean {\n\t\t// Fastify reports the https option as true rather than the options object\n\t\tconst https: unknown = this._fastify.initialConfig.https;\n\t\treturn https === true || Is.object(https);\n\t}\n\n\t/**\n\t * Whether the transport is currently listening for connections.\n\t * @returns True if the transport is listening.\n\t */\n\tprotected serverIsListening(): boolean {\n\t\treturn this._fastify?.server?.listening ?? false;\n\t}\n\n\t/**\n\t * Whether a GET route is registered for the root path.\n\t * @returns True if the root route is registered.\n\t */\n\tprotected serverHasRootRoute(): boolean {\n\t\treturn this._fastify.hasRoute({ method: \"GET\", url: \"/\" });\n\t}\n\n\t/**\n\t * Add the REST routes to the server.\n\t * @param restRouteProcessors The processors for the incoming requests.\n\t * @param restRoutes The REST routes to add.\n\t * @internal\n\t */\n\tprivate async addRoutesRest(\n\t\trestRouteProcessors?: IRestRouteProcessor[],\n\t\trestRoutes?: IRestRoute[]\n\t): Promise<void> {\n\t\tif (Is.arrayValue(restRouteProcessors) && Is.arrayValue(restRoutes)) {\n\t\t\tconst bodyLimits = this.resolveBodyLimits();\n\t\t\tfor (const restRoute of restRoutes) {\n\t\t\t\tlet path = StringHelper.trimTrailingSlashes(restRoute.path);\n\t\t\t\tif (!path.startsWith(\"/\")) {\n\t\t\t\t\tpath = `/${path}`;\n\t\t\t\t}\n\t\t\t\tawait this._logging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tsource: FastifyWebServer.CLASS_NAME,\n\t\t\t\t\tmessage: \"restRouteAdded\",\n\t\t\t\t\tdata: { route: path, method: restRoute.method }\n\t\t\t\t});\n\t\t\t\tconst method = restRoute.method.toLowerCase() as\n\t\t\t\t\t\"get\" | \"post\" | \"put\" | \"patch\" | \"delete\" | \"options\" | \"head\";\n\n\t\t\t\tconst bodyLimitKey = Is.stringValue(restRoute.bodyLimit)\n\t\t\t\t\t? restRoute.bodyLimit\n\t\t\t\t\t: HttpBodyLimit.Default;\n\t\t\t\tconst bodyLimit = bodyLimits[bodyLimitKey];\n\t\t\t\tif (Is.empty(bodyLimit)) {\n\t\t\t\t\tthrow new GeneralError(FastifyWebServer.CLASS_NAME, \"unknownBodyLimit\", {\n\t\t\t\t\t\troute: path,\n\t\t\t\t\t\tbodyLimit: bodyLimitKey\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tthis._fastify[method](path, { bodyLimit }, async (request, reply) =>\n\t\t\t\t\tthis.handleRequestRest(request, reply, restRoute)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Add the socket routes to the server.\n\t * @param socketRouteProcessors The processors for the incoming requests.\n\t * @param socketRoutes The socket routes to add.\n\t * @internal\n\t */\n\tprivate async addRoutesSocket(\n\t\tsocketRouteProcessors?: ISocketRouteProcessor[],\n\t\tsocketRoutes?: ISocketRoute[]\n\t): Promise<void> {\n\t\tif (Is.arrayValue(socketRouteProcessors) && Is.arrayValue(socketRoutes)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\tconst io: Server = (this._fastify as any).io;\n\n\t\t\tfor (const socketRoute of socketRoutes) {\n\t\t\t\tconst path = StringHelper.trimLeadingSlashes(\n\t\t\t\t\tStringHelper.trimTrailingSlashes(socketRoute.path)\n\t\t\t\t);\n\t\t\t\tconst pathParts = path.split(\"/\");\n\n\t\t\t\tconst namespace = `/${pathParts[0]}`;\n\t\t\t\tconst topic = pathParts.slice(1).join(\"/\");\n\n\t\t\t\tawait this._logging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tsource: FastifyWebServer.CLASS_NAME,\n\t\t\t\t\tmessage: \"socketRouteAdded\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\thandshakePath: this._socketConfig.path,\n\t\t\t\t\t\tnamespace,\n\t\t\t\t\t\teventName: topic\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tconst socketNamespace = io.of(namespace);\n\n\t\t\t\tsocketNamespace.on(\"connection\", async socket => {\n\t\t\t\t\tconst socketServerRequest: ISocketServerRequest = {\n\t\t\t\t\t\tmethod: HttpMethod.GET,\n\t\t\t\t\t\turl: socket.handshake.url,\n\t\t\t\t\t\tquery: socket.handshake.query as IHttpRequestQuery,\n\t\t\t\t\t\theaders: socket.handshake.headers as IHttpHeaders,\n\t\t\t\t\t\tsocketId: socket.id\n\t\t\t\t\t};\n\n\t\t\t\t\t// Pass the connected information on to any processors\n\t\t\t\t\ttry {\n\t\t\t\t\t\tfor (const connected of this._socketChains.connected) {\n\t\t\t\t\t\t\tawait connected(socketServerRequest, socketRoute, this._loggingComponentType);\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\tconst { error, httpStatusCode } = HttpErrorHelper.processError(\n\t\t\t\t\t\t\terr,\n\t\t\t\t\t\t\tthis._includeErrorStack\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst response: IHttpResponse = {};\n\t\t\t\t\t\tHttpErrorHelper.buildResponse(response, error, httpStatusCode, this._includeErrorStack);\n\t\t\t\t\t\tsocket.emit(topic, response);\n\t\t\t\t\t}\n\n\t\t\t\t\tsocket.on(\"disconnect\", async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// The socket disconnected so notify any processors\n\t\t\t\t\t\t\tfor (const disconnected of this._socketChains.disconnected) {\n\t\t\t\t\t\t\t\tawait disconnected(socketServerRequest, socketRoute, this._loggingComponentType);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// If something fails on a disconnect there is not much we can do with it\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\t// Handle any incoming messages\n\t\t\t\t\tsocket.on(topic, async data => {\n\t\t\t\t\t\t// The listener is async, so anything escaping it would surface as an unhandled\n\t\t\t\t\t\t// rejection and terminate the process, emit it on the topic instead\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait this.handleRequestSocket(\n\t\t\t\t\t\t\t\tsocketRoute,\n\t\t\t\t\t\t\t\tsocket,\n\t\t\t\t\t\t\t\t`/${pathParts.join(\"/\")}`,\n\t\t\t\t\t\t\t\ttopic,\n\t\t\t\t\t\t\t\tdata\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\tconst { error, httpStatusCode } = HttpErrorHelper.processError(\n\t\t\t\t\t\t\t\terr,\n\t\t\t\t\t\t\t\tthis._includeErrorStack\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconst response: IHttpResponse = {};\n\t\t\t\t\t\t\tHttpErrorHelper.buildResponse(\n\t\t\t\t\t\t\t\tresponse,\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t\thttpStatusCode,\n\t\t\t\t\t\t\t\tthis._includeErrorStack\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tsocket.emit(topic, response);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Handle the incoming REST request.\n\t * @param request The incoming request.\n\t * @param reply The outgoing response.\n\t * @param restRoute The REST route to handle.\n\t * @returns The Fastify reply with the response.\n\t * @internal\n\t */\n\tprivate async handleRequestRest(\n\t\trequest: FastifyRequest,\n\t\treply: FastifyReply,\n\t\trestRoute?: IRestRoute\n\t): Promise<FastifyReply> {\n\t\tconst port =\n\t\t\t(request.port === 80 && request.protocol === \"http\") ||\n\t\t\t(request.port === 443 && request.protocol === \"https\") ||\n\t\t\t!Is.integer(request.port)\n\t\t\t\t? \"\"\n\t\t\t\t: `:${request.port}`;\n\n\t\tconst requestOrigin = `${request.protocol}://${request.hostname}${port}`;\n\n\t\tconst httpServerRequest = this.buildServerRequest(\n\t\t\trequest.method.toUpperCase() as HttpMethod,\n\t\t\t`${requestOrigin}${request.url}`,\n\t\t\trequest.body,\n\t\t\trequest.query as IHttpRequestQuery,\n\t\t\t// The not found handler matches a wildcard, which is not a param of any route\n\t\t\tIs.empty(restRoute) ? {} : (request.params as IHttpRequestPathParams),\n\t\t\trequest.headers as IHttpHeaders\n\t\t);\n\n\t\tconst httpResponse: IHttpResponse = {};\n\t\tconst contextIds = this.buildContextIds(requestOrigin, httpServerRequest.headers);\n\t\tconst processorState = {};\n\n\t\tawait this.runProcessorsRest(\n\t\t\trestRoute,\n\t\t\thttpServerRequest,\n\t\t\thttpResponse,\n\t\t\tcontextIds,\n\t\t\tprocessorState\n\t\t);\n\n\t\tthis.validateResponse(httpResponse);\n\n\t\tif (!Is.empty(httpResponse.headers)) {\n\t\t\tfor (const header of Object.keys(httpResponse.headers)) {\n\t\t\t\treply.header(header, httpResponse.headers[header]);\n\t\t\t}\n\t\t}\n\t\treturn reply.status(httpResponse.statusCode ?? HttpStatusCode.ok).send(httpResponse.body);\n\t}\n\n\t/**\n\t * Handle the incoming socket request.\n\t * @param socketRoute The socket route to handle.\n\t * @param socket The socket to handle.\n\t * @param fullPath The full path of the socket route.\n\t * @param emitTopic The topic to emit the response on.\n\t * @param request The incoming request.\n\t * @internal\n\t */\n\tprivate async handleRequestSocket(\n\t\tsocketRoute: ISocketRoute,\n\t\tsocket: Socket,\n\t\tfullPath: string,\n\t\temitTopic: string,\n\t\trequest: IHttpRequest | undefined\n\t): Promise<void> {\n\t\tconst socketServerRequest: ISocketServerRequest = {\n\t\t\tmethod: HttpMethod.GET,\n\t\t\turl: fullPath,\n\t\t\tquery: socket.handshake.query as IHttpRequestQuery,\n\t\t\theaders: socket.handshake.headers as IHttpHeaders,\n\t\t\t// The payload arrives straight off the wire, so it can be missing or any shape\n\t\t\tbody: Is.object(request) ? request.body : undefined,\n\t\t\tsocketId: socket.id\n\t\t};\n\t\tconst httpResponse: IHttpResponse = {};\n\t\tconst contextIds: IContextIds = {};\n\t\tconst processorState = {};\n\n\t\tdelete socketServerRequest.query?.EIO;\n\t\tdelete socketServerRequest.query?.transport;\n\n\t\tawait this.runProcessorsSocket(\n\t\t\tsocketRoute,\n\t\t\tsocketServerRequest,\n\t\t\thttpResponse,\n\t\t\tcontextIds,\n\t\t\tprocessorState,\n\t\t\temitTopic,\n\t\t\tasync (topic, response) => {\n\t\t\t\tsocket.emit(topic, response);\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Initialize the cors options.\n\t * @param options The web server options.\n\t * @internal\n\t */\n\tprivate async initCors(options?: IWebServerOptions): Promise<void> {\n\t\tconst corsOptions = this.resolveCorsOptions(options);\n\n\t\tawait this._fastify.register(FastifyCors, {\n\t\t\torigin: (origin, callback) => {\n\t\t\t\tcallback(\n\t\t\t\t\tnull,\n\t\t\t\t\tcorsOptions.hasWildcardOrigin ? true : corsOptions.origins.includes(origin as string)\n\t\t\t\t);\n\t\t\t},\n\t\t\tmethods: corsOptions.methods,\n\t\t\tallowedHeaders: corsOptions.allowedHeaders,\n\t\t\texposedHeaders: corsOptions.exposedHeaders,\n\t\t\tcredentials: true\n\t\t});\n\t}\n}\n"]}
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
export * from "./fastifyWebServer.js";
|
|
4
|
+
export * from "./models/IFastifyWebServerConfig.js";
|
|
5
|
+
export * from "./models/IFastifyWebServerConstructorOptions.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qCAAqC,CAAC;AACpD,cAAc,iDAAiD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./fastifyWebServer.js\";\nexport * from \"./models/IFastifyWebServerConfig.js\";\nexport * from \"./models/IFastifyWebServerConstructorOptions.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IFastifyWebServerConfig.js","sources":["../../../src/models/IFastifyWebServerConfig.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ServerOptions as HttpsServerOptions } from \"node:https\";\nimport type { FastifyServerOptions } from \"fastify\";\nimport type { ServerOptions } from \"socket.io\";\n\n/**\n * The configuration for the Fastify web server.\n */\nexport interface IFastifyWebServerConfig {\n\t/**\n\t * The web server options, providing the https options serves over HTTPS.\n\t */\n\tweb?: Partial<FastifyServerOptions> & { https?: HttpsServerOptions };\n\n\t/**\n\t * The socket server options.\n\t */\n\tsocket?: Partial<ServerOptions>;\n\n\t/**\n\t * Include the stack with errors.\n\t */\n\tincludeErrorStack?: boolean;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IFastifyWebServerConstructorOptions.js","sources":["../../../src/models/IFastifyWebServerConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IMimeTypeProcessor } from \"@3sixty/api-models\";\nimport type { IFastifyWebServerConfig } from \"./IFastifyWebServerConfig.js\";\n\n/**\n * The options for the Fastify web server constructor.\n */\nexport interface IFastifyWebServerConstructorOptions {\n\t/**\n\t * The type of the logging component to use, if undefined, no logging will happen.\n\t */\n\tloggingComponentType?: string;\n\n\t/**\n\t * Additional configuration for the server.\n\t */\n\tconfig?: IFastifyWebServerConfig;\n\n\t/**\n\t * Additional MIME type processors.\n\t */\n\tmimeTypeProcessors?: IMimeTypeProcessor[];\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FastifyPluginAsync } from "fastify";
|
|
2
|
+
import { type ServerOptions } from "socket.io";
|
|
3
|
+
/**
|
|
4
|
+
* Fastify plugin that attaches a Socket.IO server to the Fastify HTTP server.
|
|
5
|
+
* Cloned from fastify-socket.io to support recent Fastify versions.
|
|
6
|
+
*/
|
|
7
|
+
declare const fastifySocketIO: FastifyPluginAsync<Partial<ServerOptions>>;
|
|
8
|
+
export default fastifySocketIO;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { BaseServer } from "@3sixty/api-core-server";
|
|
2
|
+
import { type IRestRoute, type IRestRouteProcessor, type ISocketRoute, type ISocketRouteProcessor, type IWebServerOptions } from "@3sixty/api-models";
|
|
3
|
+
import { type FastifyInstance } from "fastify";
|
|
4
|
+
import type { IFastifyWebServerConstructorOptions } from "./models/IFastifyWebServerConstructorOptions.js";
|
|
5
|
+
/**
|
|
6
|
+
* Implementation of the web server using Fastify.
|
|
7
|
+
*/
|
|
8
|
+
export declare class FastifyWebServer extends BaseServer<FastifyInstance> {
|
|
9
|
+
/**
|
|
10
|
+
* Runtime name for the class.
|
|
11
|
+
*/
|
|
12
|
+
static readonly CLASS_NAME: string;
|
|
13
|
+
/**
|
|
14
|
+
* Create a new instance of FastifyWebServer.
|
|
15
|
+
* @param options The options for the server.
|
|
16
|
+
*/
|
|
17
|
+
constructor(options?: IFastifyWebServerConstructorOptions);
|
|
18
|
+
/**
|
|
19
|
+
* Returns the class name of the component.
|
|
20
|
+
* @returns The class name of the component.
|
|
21
|
+
*/
|
|
22
|
+
className(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get the web server instance.
|
|
25
|
+
* @returns The web server instance.
|
|
26
|
+
*/
|
|
27
|
+
getInstance(): FastifyInstance;
|
|
28
|
+
/**
|
|
29
|
+
* Build the server.
|
|
30
|
+
* @param restRouteProcessors The processors for incoming requests over REST.
|
|
31
|
+
* @param restRoutes The REST routes.
|
|
32
|
+
* @param socketRouteProcessors The processors for incoming requests over Sockets.
|
|
33
|
+
* @param socketRoutes The socket routes.
|
|
34
|
+
* @param options Options for building the server.
|
|
35
|
+
* @returns A promise that resolves when the server is fully built and ready to start.
|
|
36
|
+
*/
|
|
37
|
+
build(restRouteProcessors?: IRestRouteProcessor[], restRoutes?: IRestRoute[], socketRouteProcessors?: ISocketRouteProcessor[], socketRoutes?: ISocketRoute[], options?: IWebServerOptions): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Start listening for connections on the transport.
|
|
40
|
+
* @param host The host to bind to.
|
|
41
|
+
* @param port The port to bind to.
|
|
42
|
+
* @returns A promise that resolves when the transport is listening.
|
|
43
|
+
*/
|
|
44
|
+
protected serverListen(host: string, port: number): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Close the transport and all of its connections.
|
|
47
|
+
* @returns A promise that resolves when the transport has closed.
|
|
48
|
+
*/
|
|
49
|
+
protected serverClose(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Get the addresses the transport is bound to.
|
|
52
|
+
* @returns The bound addresses.
|
|
53
|
+
*/
|
|
54
|
+
protected serverAddresses(): {
|
|
55
|
+
address: string;
|
|
56
|
+
family?: string;
|
|
57
|
+
port: number;
|
|
58
|
+
}[];
|
|
59
|
+
/**
|
|
60
|
+
* Whether the transport is serving over TLS.
|
|
61
|
+
* @returns True if the transport is secure.
|
|
62
|
+
*/
|
|
63
|
+
protected serverIsSecure(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Whether the transport is currently listening for connections.
|
|
66
|
+
* @returns True if the transport is listening.
|
|
67
|
+
*/
|
|
68
|
+
protected serverIsListening(): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Whether a GET route is registered for the root path.
|
|
71
|
+
* @returns True if the root route is registered.
|
|
72
|
+
*/
|
|
73
|
+
protected serverHasRootRoute(): boolean;
|
|
74
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ServerOptions as HttpsServerOptions } from "node:https";
|
|
2
|
+
import type { FastifyServerOptions } from "fastify";
|
|
3
|
+
import type { ServerOptions } from "socket.io";
|
|
4
|
+
/**
|
|
5
|
+
* The configuration for the Fastify web server.
|
|
6
|
+
*/
|
|
7
|
+
export interface IFastifyWebServerConfig {
|
|
8
|
+
/**
|
|
9
|
+
* The web server options, providing the https options serves over HTTPS.
|
|
10
|
+
*/
|
|
11
|
+
web?: Partial<FastifyServerOptions> & {
|
|
12
|
+
https?: HttpsServerOptions;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The socket server options.
|
|
16
|
+
*/
|
|
17
|
+
socket?: Partial<ServerOptions>;
|
|
18
|
+
/**
|
|
19
|
+
* Include the stack with errors.
|
|
20
|
+
*/
|
|
21
|
+
includeErrorStack?: boolean;
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IMimeTypeProcessor } from "@3sixty/api-models";
|
|
2
|
+
import type { IFastifyWebServerConfig } from "./IFastifyWebServerConfig.js";
|
|
3
|
+
/**
|
|
4
|
+
* The options for the Fastify web server constructor.
|
|
5
|
+
*/
|
|
6
|
+
export interface IFastifyWebServerConstructorOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The type of the logging component to use, if undefined, no logging will happen.
|
|
9
|
+
*/
|
|
10
|
+
loggingComponentType?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Additional configuration for the server.
|
|
13
|
+
*/
|
|
14
|
+
config?: IFastifyWebServerConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Additional MIME type processors.
|
|
17
|
+
*/
|
|
18
|
+
mimeTypeProcessors?: IMimeTypeProcessor[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.20.0-next.1](https://github.com/3sixtyglobal/api/compare/api-server-fastify-v0.20.0-next.0...api-server-fastify-v0.20.0-next.1) (2026-10-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* authorization ([#51](https://github.com/3sixtyglobal/api/issues/51)) ([023ef94](https://github.com/3sixtyglobal/api/commit/023ef94925114e88522cbe6f703d9b05a202bc6d))
|
|
9
|
+
* publish packages under the [@3sixty](https://github.com/3sixty) namespace ([91b1822](https://github.com/3sixtyglobal/api/commit/91b1822dba38f70692087ad4643572531d6634dc))
|
|
10
|
+
* updated ts compile ([d9a5c86](https://github.com/3sixtyglobal/api/commit/d9a5c86ec7dd1faf3045b5cd1e0d38a4b331313d))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Dependencies
|
|
14
|
+
|
|
15
|
+
* The following workspace dependencies were updated
|
|
16
|
+
* dependencies
|
|
17
|
+
* @3sixty/api-core-server bumped from 0.20.0-next.0 to 0.20.0-next.1
|
|
18
|
+
* @3sixty/api-core bumped from 0.20.0-next.0 to 0.20.0-next.1
|
|
19
|
+
* @3sixty/api-models bumped from 0.20.0-next.0 to 0.20.0-next.1
|
|
20
|
+
* devDependencies
|
|
21
|
+
* @3sixty/api-processors bumped from 0.20.0-next.0 to 0.20.0-next.1
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Server Fastify Examples
|
|
2
|
+
|
|
3
|
+
Use these snippets to build and run the Fastify server with explicit lifecycle control in scripts and integration tests.
|
|
4
|
+
|
|
5
|
+
## FastifyWebServer
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { FastifyWebServer } from '@3sixty/api-server-fastify';
|
|
9
|
+
|
|
10
|
+
const webServer = new FastifyWebServer();
|
|
11
|
+
|
|
12
|
+
await webServer.build(undefined, undefined, undefined, undefined, {
|
|
13
|
+
port: 8080,
|
|
14
|
+
host: '0.0.0.0'
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
await webServer.start();
|
|
18
|
+
const instance = webServer.getInstance();
|
|
19
|
+
|
|
20
|
+
console.log(instance.server.address() !== null); // true
|
|
21
|
+
|
|
22
|
+
await webServer.stop();
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { FastifyWebServer } from '@3sixty/api-server-fastify';
|
|
27
|
+
|
|
28
|
+
const webServer = new FastifyWebServer();
|
|
29
|
+
|
|
30
|
+
await webServer.build(undefined, undefined, undefined, undefined, {
|
|
31
|
+
port: 3000,
|
|
32
|
+
host: '127.0.0.1'
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
await webServer.start();
|
|
36
|
+
await webServer.stop();
|
|
37
|
+
```
|