@alwatr/nanotron-api-server 4.6.0 → 4.8.0

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/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.8.0](https://github.com/Alwatr/nanotron/compare/v4.7.0...v4.8.0) (2024-11-08)
7
+
8
+ ### Features
9
+
10
+ * **api-server:** refactor CORS handling to use new crossOrigin configuration ([52a40d7](https://github.com/Alwatr/nanotron/commit/52a40d741124b78e7fdfc4207e591a4e620b2446)) by @
11
+
12
+ ## [4.7.0](https://github.com/Alwatr/nanotron/compare/v4.6.0...v4.7.0) (2024-11-07)
13
+
14
+ ### Features
15
+
16
+ * **api-server:** set `allowOrigin` from configs ([8add97c](https://github.com/Alwatr/nanotron/commit/8add97cac9d29e4a7ce26ee487896183dabea135)) by @mohammadhonarvar
17
+
6
18
  ## [4.6.0](https://github.com/Alwatr/nanotron/compare/v4.5.2...v4.6.0) (2024-11-07)
7
19
 
8
20
  ### Features
@@ -1 +1 @@
1
- {"version":3,"file":"api-server-response.d.ts","sourceRoot":"","sources":["../src/api-server-response.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,KAAK,cAAc,EAAsC,MAAM,YAAY,CAAC;AAEpF,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAC,mBAAmB,EAAE,aAAa,EAAE,oBAAoB,EAAC,MAAM,WAAW,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,aAAa,EAAE,qBAAqB,CAAC;CACtC;AAED,qBAAa,sBAAsB;IACjC,QAAQ,CAAC,aAAa,EAAE,qBAAqB,CAAC;IAE9C,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IAEpC,QAAQ,CAAC,OAAO,EAAE,m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AAoB,EAAE,oBAAoB;IAwBpG,IAAI,UAAU,IAAI,cAAc,CAE/B;IAED,IAAI,UAAU,CAAC,KAAK,EAAE,cAAc,EAEnC;IAED,SAAS,CAAC,aAAa;IAOvB,kBAAkB,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI;IAsBtD,UAAU,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI;IAoCzD,SAAS,CAAC,YAAY,EAAE,IAAI,GAAG,IAAI;IAsBnC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAmCtC"}
@@ -44,11 +44,17 @@ export interface NanotronApiServerConfig {
44
44
  */
45
45
  healthRoute?: boolean;
46
46
  /**
47
- * Add OPTIONS route for preflight requests to allow access all origins.
47
+ * Add OPTIONS route for preflight requests to allow access origins.
48
48
  *
49
- * @default false
49
+ * @default {enable: false, origin: '*', methods: '*', headers: '*', maxAge: 86_400}
50
50
  */
51
- allowAllOrigin?: boolean;
51
+ crossOrigin?: {
52
+ enable: boolean;
53
+ origin: string;
54
+ methods: string;
55
+ headers: string;
56
+ maxAge: string | number;
57
+ };
52
58
  /**
53
59
  * A prefix to be added to the beginning of the `url` of all defined routes.
54
60
  *
@@ -64,17 +70,7 @@ export interface NanotronApiServerConfig {
64
70
  }
65
71
  export declare class NanotronApiServer {
66
72
  protected static readonly defaultConfig_: Readonly<Required<NanotronApiServerConfig>>;
67
- readonly config_: {
68
- port: number;
69
- host: string;
70
- requestTimeout: number;
71
- headersTimeout: number;
72
- keepAliveTimeout: number;
73
- healthRoute: boolean;
74
- allowAllOrigin: boolean;
75
- prefix: `/${string}/` | "/";
76
- bodyLimit: number;
77
- };
73
+ readonly config_: Required<NanotronApiServerConfig>;
78
74
  protected readonly logger_: import("@alwatr/logger").AlwatrLogger;
79
75
  readonly httpServer: import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
80
76
  protected readonly routeHandlerList__: Record<MatchType, DictionaryOpt<DictionaryOpt<Required<DefineRouteOption>>>>;
@@ -1 +1 @@
1
- {"version":3,"file":"api-server.d.ts","sourceRoot":"","sources":["../src/api-server.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,WAAW,EAAC,MAAM,UAAU,CAAC;AAErC,OAAO,KAAK,EAAC,iBAAiB,EAAE,SAAS,EAAE,mBAAmB,EAAE,oBAAoB,EAAC,MAAM,WAAW,CAAC;AACvG,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAIxC;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;OAIG;IACH,MAAM,CAAC,EAAE,IAAI,MAAM,GAAG,GAAG,GAAG,CAAC;IAE7B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,iBAAiB;IAC5B,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,QAAQ,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAAC,CAUnF;IAEF,QAAQ,CAAC,OAAO;cA1ET,MAAM;cAON,MAAM;wBAOI,MAAM;wBASN,MAAM;0BAOJ,MAAM;qBAOX,OAAO;wBAOJ,OAAO;gBAOf,IAAI,MAAM,GAAG,GAAG,GAAG;mBAOhB,MAAM;MAgBD;IACjB,SAAS,CAAC,QAAQ,CAAC,OAAO,wCAAC;IAE3B,QAA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B/E,SAAS,CAAC,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,iBAAiB,CAAC,GAAG,IAAI;IAepE,WAAW,CAAC,WAAW,SAAS,aAAa,GAAG,aAAa,EAAE,MAAM,EAAE,iBAAiB,CAAC,WAAW,CAAC,GAAG,IAAI;IAa5G,SAAS,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,cAAc,GAAG,IAAI;IAShE,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;cAoB9D,oBAAoB,CAClC,mBAAmB,EAAE,mBAAmB,EACxC,oBAAoB,EAAE,oBAAoB,GACzC,OAAO,CAAC,IAAI,CAAC;IA6ChB,SAAS,CAAC,kBAAkB,IAAI,IAAI;IAgBpC,SAAS,CAAC,gBAAgB,IAAI,IAAI;CAqBnC"}
package/dist/main.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /* @alwatr/nanotron-api-server v4.6.0 */
1
+ /* @alwatr/nanotron-api-server v4.8.0 */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -417,8 +417,15 @@ var NanotronServerResponse = class {
417
417
  this.logger_.logMethodArgs?.("new", this.clientRequest.url.debugId);
418
418
  this.headers = {
419
419
  server: "Alwatr Nanotron",
420
- "content-type": "text/plain"
420
+ "content-type": "text/plain charset=UTF-8"
421
421
  };
422
+ const crossOrigin = this.clientRequest.routeOption?.crossOrigin;
423
+ if (crossOrigin?.enable === true) {
424
+ this.headers["access-control-allow-origin"] = crossOrigin.origin;
425
+ this.headers["access-control-allow-methods"] = crossOrigin.methods;
426
+ this.headers["access-control-allow-headers"] = crossOrigin.headers;
427
+ this.headers["access-control-max-age"] = crossOrigin.maxAge;
428
+ }
422
429
  }
423
430
  get hasBeenSent() {
424
431
  return this.hasBeenSent_;
@@ -631,7 +638,7 @@ _NanotronUrl.versionPattern_ = new RegExp("^/v[0-9]+/");
631
638
  var NanotronUrl = _NanotronUrl;
632
639
 
633
640
  // src/api-server.ts
634
- __dev_mode__: import_nanolib3.packageTracer.add("@alwatr/nanotron-api-server", "4.6.0");
641
+ __dev_mode__: import_nanolib3.packageTracer.add("@alwatr/nanotron-api-server", "4.8.0");
635
642
  var _NanotronApiServer = class _NanotronApiServer {
636
643
  constructor(config) {
637
644
  this.config_ = {
@@ -663,12 +670,10 @@ var _NanotronApiServer = class _NanotronApiServer {
663
670
  });
664
671
  this.httpServer.on("error", this.handleServerError_);
665
672
  this.httpServer.on("clientError", this.handleClientError_);
673
+ this.defineCorsRoute_();
666
674
  if (this.config_.healthRoute) {
667
675
  this.defineHealthRoute_();
668
676
  }
669
- if (this.config_.allowAllOrigin === true) {
670
- this.defineCorsRoute_();
671
- }
672
677
  }
673
678
  close() {
674
679
  this.logger_.logMethod?.("close");
@@ -707,6 +712,7 @@ var _NanotronApiServer = class _NanotronApiServer {
707
712
  preHandlers: [],
708
713
  postHandlers: [],
709
714
  bodyLimit: this.config_.bodyLimit,
715
+ crossOrigin: this.config_.crossOrigin,
710
716
  ...option
711
717
  };
712
718
  this.logger_.logMethodArgs?.("defineRoute", option_);
@@ -744,9 +750,6 @@ var _NanotronApiServer = class _NanotronApiServer {
744
750
  const url = new NanotronUrl(nativeClientRequest, this.config_.prefix);
745
751
  const routeOption = this.getRouteOption_(url);
746
752
  const connection = new NanotronClientRequest(url, nativeClientRequest, nativeServerResponse, routeOption);
747
- if (this.config_.allowAllOrigin === true) {
748
- connection.serverResponse.headers["access-control-allow-origin"] = "*";
749
- }
750
753
  if (routeOption === null) {
751
754
  connection.serverResponse.statusCode = HttpStatusCodes.Error_Client_404_Not_Found;
752
755
  connection.serverResponse.replyError();
@@ -786,16 +789,21 @@ var _NanotronApiServer = class _NanotronApiServer {
786
789
  }
787
790
  defineCorsRoute_() {
788
791
  this.logger_.logMethod?.("defineCorsRoute_");
792
+ const crossOrigin = this.config_.crossOrigin;
793
+ if (crossOrigin?.enable !== true) return;
789
794
  this.defineRoute({
790
795
  method: "OPTIONS",
791
796
  matchType: "startsWith",
792
797
  url: "/",
793
798
  handler: function() {
794
799
  const res = this.serverResponse.raw_;
795
- res.statusCode = HttpStatusCodes.Success_204_No_Content;
796
- res.setHeader("access-control-allow-origin", "*");
797
- res.setHeader("access-control-allow-methods", "*");
798
- res.setHeader("access-control-allow-headers", "*");
800
+ res.writeHead(HttpStatusCodes.Success_204_No_Content, {
801
+ "access-control-allow-origin": crossOrigin.origin,
802
+ "access-control-allow-methods": crossOrigin.methods,
803
+ "access-control-allow-headers": crossOrigin.headers,
804
+ "access-control-max-age": crossOrigin.maxAge + "",
805
+ "content-length": 0
806
+ });
799
807
  res.end();
800
808
  }
801
809
  });
@@ -808,7 +816,14 @@ _NanotronApiServer.defaultConfig_ = {
808
816
  headersTimeout: 13e4,
809
817
  keepAliveTimeout: 12e4,
810
818
  healthRoute: true,
811
- allowAllOrigin: false,
819
+ crossOrigin: {
820
+ enable: false,
821
+ origin: "*",
822
+ methods: "*",
823
+ headers: "*",
824
+ maxAge: 86400
825
+ // 24h
826
+ },
812
827
  prefix: "/api/",
813
828
  bodyLimit: 1048576
814
829
  // 1MiB
package/dist/main.cjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/main.ts", "../src/api-server.ts", "../src/api-client-request.ts", "../src/api-server-response.ts", "../src/const.ts", "../src/url.ts"],
4
- "sourcesContent": ["export * from './api-server.js';\nexport * from './type.js';\nexport * from './const.js';\n\nexport type {NanotronClientRequest} from './api-client-request.js';\nexport type {NanotronServerResponse} from './api-server-response.js';\nexport type {NanotronUrl} from './url.js';\n", "import {createServer} from 'node:http';\n\nimport {createLogger, packageTracer} from '@alwatr/nanolib';\n\nimport {NanotronClientRequest} from './api-client-request.js';\nimport {HttpStatusCodes, HttpStatusMessages} from './const.js';\nimport {NanotronUrl} from './url.js';\n\nimport type {DefineRouteOption, MatchType, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {Duplex} from 'node:stream';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Configuration options for the NanotronApiServer.\n */\nexport interface NanotronApiServerConfig {\n /**\n * The port number to listen on.\n *\n * @default 80\n */\n port?: number;\n\n /**\n * The hostname to listen on.\n *\n * @default '0.0.0.0'\n */\n host?: string;\n\n /**\n * Sets the timeout (ms) for receiving the entire request from the client.\n *\n * @default 10_000 ms\n */\n requestTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * This should be bigger than `keepAliveTimeout + your server's expected response time`.\n *\n * @default 130_000 ms\n */\n headersTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * @default 120_000 ms\n */\n keepAliveTimeout?: number;\n\n /**\n * Add /health route.\n *\n * @default true\n */\n healthRoute?: boolean;\n\n /**\n * Add OPTIONS route for preflight requests to allow access all origins.\n *\n * @default false\n */\n allowAllOrigin?: boolean;\n\n /**\n * A prefix to be added to the beginning of the `url` of all defined routes.\n *\n * @default '/api/'\n */\n prefix?: `/${string}/` | '/';\n\n /**\n * The maximum size of the request body in bytes.\n *\n * @default `1_048_576` (1MiB)\n */\n bodyLimit?: number;\n}\n\nexport class NanotronApiServer {\n protected static readonly defaultConfig_: Readonly<Required<NanotronApiServerConfig>> = {\n host: '0.0.0.0',\n port: 80,\n requestTimeout: 10_000,\n headersTimeout: 130_000,\n keepAliveTimeout: 120_000,\n healthRoute: true,\n allowAllOrigin: false,\n prefix: '/api/',\n bodyLimit: 1_048_576, // 1MiB\n };\n\n readonly config_;\n protected readonly logger_;\n\n readonly httpServer;\n\n protected readonly routeHandlerList__: Record<MatchType, DictionaryOpt<DictionaryOpt<Required<DefineRouteOption>>>>;\n\n constructor(config?: Partial<NanotronApiServerConfig>) {\n // Merge the config with the default config.\n this.config_ = {\n ...NanotronApiServer.defaultConfig_,\n ...config,\n };\n\n // Create logger.\n this.logger_ = createLogger('nt-api-server' + (this.config_.port !== 80 ? ':' + this.config_.port : ''));\n this.logger_.logMethodArgs?.('new', {config: this.config_});\n\n // Bind methods.\n this.handleClientRequest_ = this.handleClientRequest_.bind(this);\n this.handleServerError_ = this.handleServerError_.bind(this);\n this.handleClientError_ = this.handleClientError_.bind(this);\n\n // Initialize route handler list.\n this.routeHandlerList__ = {\n exact: {},\n startsWith: {},\n };\n\n // Create the HTTP server.\n this.httpServer = createServer(\n {\n keepAlive: true,\n keepAliveInitialDelay: 0,\n noDelay: true,\n },\n this.handleClientRequest_,\n );\n\n // Configure the server.\n this.httpServer.requestTimeout = this.config_.requestTimeout;\n this.httpServer.keepAliveTimeout = this.config_.keepAliveTimeout;\n this.httpServer.headersTimeout = this.config_.headersTimeout;\n\n // Start the server.\n this.httpServer.listen(this.config_.port, this.config_.host, () => {\n this.logger_.logOther?.(`listening on ${this.config_.host}:${this.config_.port}`);\n });\n\n // Handle server errors.\n this.httpServer.on('error', this.handleServerError_);\n this.httpServer.on('clientError', this.handleClientError_);\n\n if (this.config_.healthRoute) {\n this.defineHealthRoute_();\n }\n\n if (this.config_.allowAllOrigin === true) {\n this.defineCorsRoute_();\n }\n }\n\n close(): void {\n this.logger_.logMethod?.('close');\n this.httpServer.close();\n }\n\n protected getRouteOption_(url: NanotronUrl): Required<DefineRouteOption> | null {\n this.logger_.logMethod?.('getRouteOption_');\n\n if (\n Object.hasOwn(this.routeHandlerList__.exact, url.method) &&\n Object.hasOwn(this.routeHandlerList__.exact[url.method]!, url.pathname)\n ) {\n return this.routeHandlerList__.exact[url.method]![url.pathname]!;\n }\n\n if (Object.hasOwn(this.routeHandlerList__.startsWith, url.method)) {\n const routeList = this.routeHandlerList__.startsWith[url.method];\n for (const pathname in routeList) {\n if (pathname.indexOf(url.pathname) === 0) {\n return routeList[pathname]!;\n }\n }\n }\n\n this.logger_.incident?.('getRouteOption_', 'route_not_found', {method: url.method, url: url.pathname});\n return null;\n }\n\n protected setRouteOption_(option: Required<DefineRouteOption>): void {\n this.logger_.logMethodArgs?.('setRouteOption_', option);\n\n const routeHandlerList = this.routeHandlerList__[option.matchType];\n\n routeHandlerList[option.method] ??= {};\n\n if (Object.hasOwn(routeHandlerList[option.method]!, option.url)) {\n this.logger_.error('defineRoute', 'route_already_exists', option);\n throw new Error('route_already_exists');\n }\n\n routeHandlerList[option.method]![option.url] = option;\n }\n\n defineRoute<TSharedMeta extends DictionaryOpt = DictionaryOpt>(option: DefineRouteOption<TSharedMeta>): void {\n const option_: Required<DefineRouteOption<TSharedMeta>> = {\n matchType: 'exact',\n preHandlers: [],\n postHandlers: [],\n bodyLimit: this.config_.bodyLimit,\n ...option,\n };\n this.logger_.logMethodArgs?.('defineRoute', option_);\n this.setRouteOption_(option_ as Required<DefineRouteOption>);\n }\n\n protected handleServerError_(error: NodeJS.ErrnoException): void {\n if (error.code === 'EADDRINUSE') {\n this.logger_.error('handleServerError_', 'address_in_use', error);\n }\n else {\n this.logger_.error('handleServerError_', 'http_server_error', error);\n }\n }\n\n protected handleClientError_(err: NodeJS.ErrnoException, socket: Duplex): void {\n this.logger_.accident('handleClientError_', 'http_server_client_error', {\n errCode: err.code,\n errMessage: err.message,\n });\n\n const errorCode = err.code?.toLowerCase() ?? `error_${HttpStatusCodes.Error_Client_400_Bad_Request}`;\n const errorMessage = err.message ?? HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request];\n const errorResponse = `{\"ok\":false,\"errorCode\":\"${errorCode}\",\"errorMessage\":\"${errorMessage}\"}`;\n\n const responseHeaders = [\n `HTTP/1.1 ${HttpStatusCodes.Error_Client_400_Bad_Request} ${HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request]}`,\n 'content-type: application/json',\n `content-length: ${Buffer.byteLength(errorResponse)}`,\n '\\r\\n',\n ].join('\\r\\n');\n\n socket.end(responseHeaders + errorResponse);\n }\n\n protected async handleClientRequest_(\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n ): Promise<void> {\n this.logger_.logMethod?.('handleClientRequest_');\n\n if (nativeClientRequest.url === undefined) {\n this.logger_.accident('handleClientRequest_', 'http_server_url_undefined');\n return;\n }\n\n const url = new NanotronUrl(nativeClientRequest, this.config_.prefix);\n\n const routeOption = this.getRouteOption_(url);\n\n const connection = new NanotronClientRequest(url, nativeClientRequest, nativeServerResponse, routeOption);\n\n if (this.config_.allowAllOrigin === true) {\n connection.serverResponse.headers['access-control-allow-origin'] = '*';\n }\n\n if (routeOption === null) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Client_404_Not_Found;\n connection.serverResponse.replyError();\n return;\n }\n\n try {\n for (const handler of routeOption.preHandlers) {\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n if (connection.terminatedHandlers === true) return; // must check after each pre-handler.\n }\n\n await routeOption.handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n\n for (const handler of routeOption.postHandlers) {\n if (connection.terminatedHandlers === true) return; // must check before each post-handler.\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n }\n }\n catch (error) {\n this.logger_.error('handleClientRequest_', 'route_handler_error', error, url.debugId);\n\n if (connection.serverResponse.statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n }\n connection.serverResponse.replyError(error);\n }\n\n // TODO: handled open remained connections.\n }\n\n protected defineHealthRoute_(): void {\n this.logger_.logMethod?.('defineHealthRoute_');\n\n this.defineRoute({\n method: 'GET',\n url: '/health',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.statusCode = HttpStatusCodes.Success_200_OK;\n res.setHeader('server', 'Alwatr Nanotron');\n res.setHeader('content-type', 'application/json');\n res.end('{\"ok\":true}');\n },\n });\n }\n\n protected defineCorsRoute_(): void {\n this.logger_.logMethod?.('defineCorsRoute_');\n\n this.defineRoute({\n method: 'OPTIONS',\n matchType: 'startsWith',\n url: '/',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.statusCode = HttpStatusCodes.Success_204_No_Content;\n res.setHeader('access-control-allow-origin', '*');\n res.setHeader('access-control-allow-methods', '*');\n res.setHeader('access-control-allow-headers', '*');\n res.end();\n },\n });\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {NanotronServerResponse} from './api-server-response.js';\nimport {HttpStatusCodes} from './const.js';\n\nimport type {DefineRouteOption, HttpRequestHeaders, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {NanotronUrl} from './url.js';\n\nexport class NanotronClientRequest<TSharedMeta extends DictionaryOpt = DictionaryOpt> {\n readonly url: NanotronUrl;\n\n readonly serverResponse: NanotronServerResponse;\n\n readonly routeOption: Required<DefineRouteOption> | null;\n\n /**\n * A flag to indicate if the running handlers queue has been terminated.\n * This can occur due to an error being thrown or by explicitly calling the `replyError` method.\n *\n * When `terminatedHandlers` is set to `true`, it signifies that the execution of the current\n * sequence of handlers (including pre, main, and post handlers) has been halted and no further\n * handlers in the queue will be executed.\n *\n * Usage:\n * - Check this flag to determine if the handlers queue has been interrupted.\n * - Set this flag to `true` to manually stop the execution of subsequent handlers.\n */\n terminatedHandlers?: true;\n\n readonly sharedMeta: TSharedMeta = {} as TSharedMeta;\n\n readonly raw_: NativeClientRequest;\n\n protected readonly logger_;\n\n readonly remoteAddress: string | null;\n\n get headers(): HttpRequestHeaders {\n return this.raw_.headers;\n }\n\n private queryParams__?: DictionaryOpt<string>;\n get queryParams(): DictionaryOpt<string> {\n if (this.queryParams__ === undefined) {\n this.queryParams__ = {};\n for (const [key, value] of this.url.searchParams.entries()) {\n this.queryParams__[key] = value;\n }\n }\n return this.queryParams__;\n }\n\n constructor(\n url: NanotronUrl,\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n routeOption: Required<DefineRouteOption> | null,\n ) {\n // Store public properties.\n this.raw_ = nativeClientRequest;\n this.url = url;\n this.routeOption = routeOption;\n\n // Get and store remote address.\n this.remoteAddress = this.getRemoteAddress__();\n\n // Create logger.\n this.logger_ = createLogger(`nt-client-request(${this.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', url.debugId);\n\n // Create server response.\n this.serverResponse = new NanotronServerResponse(this, nativeServerResponse);\n }\n\n getBodyRaw(): Promise<Buffer> {\n return new Promise((resolve, reject) => {\n // method must be POST or PUT or PATCH\n const method = this.url.method;\n if (!(method === 'POST' || method === 'PUT' || method === 'PATCH')) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_405_Method_Not_Allowed;\n return reject(new Error('body_not_allowed'));\n }\n\n const contentLength = +this.raw_.headers['content-length']!;\n\n if (Number.isNaN(contentLength) || contentLength === 0) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_411_Length_Required;\n return reject(new Error('body_length_required'));\n }\n\n if (contentLength > this.routeOption!.bodyLimit) {\n // TODO: routeOption when null?!\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const dataChunks: Uint8Array[] = [];\n let receivedLength = 0;\n\n const onData = (chunk: Uint8Array) => {\n receivedLength += chunk.length;\n dataChunks.push(chunk);\n\n if (receivedLength > this.routeOption!.bodyLimit) {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n dataChunks.length = 0; // free memory\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n };\n\n const onEnd = (err?: Error) => {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n\n if (err !== undefined) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_400_Bad_Request;\n return reject(err);\n }\n\n if (receivedLength !== contentLength) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const body = Buffer.concat(dataChunks);\n\n resolve(body);\n };\n\n this.raw_.on('data', onData);\n this.raw_.on('end', onEnd);\n this.raw_.on('error', onEnd);\n this.raw_.resume();\n });\n }\n\n private getRemoteAddress__(): string | null {\n return this.raw_.headers['x-forwarded-for']?.split(',').pop()?.trim() || this.raw_.socket.remoteAddress || null;\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {type HttpStatusCode, HttpStatusCodes, HttpStatusMessages} from './const.js';\n\nimport type {NanotronClientRequest} from './api-client-request.js';\nimport type {HttpResponseHeaders, ErrorResponse, NativeServerResponse} from './type.js';\n\n/**\n * Configuration options for the Nanotron Api Server Response.\n */\nexport interface NanotronServerResponseConfig {\n clientRequest: NanotronClientRequest;\n}\n\nexport class NanotronServerResponse {\n readonly clientRequest: NanotronClientRequest;\n\n readonly raw_: NativeServerResponse;\n\n readonly headers: HttpResponseHeaders;\n\n protected readonly logger_;\n\n protected hasBeenSent_ = false;\n get hasBeenSent(): boolean {\n return this.hasBeenSent_;\n }\n\n constructor(nanotronClientRequest: NanotronClientRequest, nativeServerResponse: NativeServerResponse) {\n // Store public properties.\n this.clientRequest = nanotronClientRequest;\n this.raw_ = nativeServerResponse;\n\n // Create logger.\n this.logger_ = createLogger(`nt-server-response(${this.clientRequest.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', this.clientRequest.url.debugId);\n\n // Set default reply headers.\n this.headers = {\n server: 'Alwatr Nanotron',\n 'content-type': 'text/plain',\n };\n }\n\n get statusCode(): HttpStatusCode {\n return this.raw_.statusCode as HttpStatusCode;\n }\n\n set statusCode(value: HttpStatusCode) {\n this.raw_.statusCode = value;\n }\n\n protected applyHeaders_() {\n this.logger_.logMethodArgs?.('applyHeaders_', this.headers);\n for (const key in this.headers) {\n this.raw_.setHeader(key, this.headers[key as Lowercase<string>]!);\n }\n }\n\n replyErrorResponse(errorResponse: ErrorResponse): void {\n this.logger_.logMethod?.('replyErrorResponse');\n this.clientRequest.terminatedHandlers = true;\n this.headers['content-type'] = 'application/json';\n let meta = '';\n if (errorResponse.meta !== undefined) {\n const metaType = typeof errorResponse.meta;\n if (\n metaType === 'string' ||\n metaType === 'number' ||\n metaType === 'boolean' ||\n errorResponse.meta === null) {\n meta = `,\"meta\":\"${errorResponse.meta}\"`;\n }\n else if (metaType === 'object') {\n meta = `,\"meta\":${JSON.stringify(errorResponse.meta)}`;\n }\n }\n const responseString = `{\"ok\":false,\"errorCode\":\"${errorResponse.errorCode}\",\"errorMessage\":\"${errorResponse.errorMessage}\"${meta}}`;\n this.reply(responseString);\n }\n\n replyError(error?: Error | string | Json | unknown): void {\n this.logger_.logMethodArgs?.('replyError', {error});\n\n this.clientRequest.terminatedHandlers = true;\n let statusCode = this.statusCode;\n\n if (statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n this.statusCode = statusCode = 500;\n }\n\n if (error instanceof Error) {\n this.replyErrorResponse({\n ok: false,\n errorCode: (error.name === 'Error' ? 'error_' + statusCode : (error.name + '').toLowerCase()) as Lowercase<string>,\n errorMessage: error.message,\n });\n }\n else if (typeof error === 'string') {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: error,\n });\n }\n else if (typeof error === 'object' && error !== null) {\n this.replyJson(error as Json);\n }\n else {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: HttpStatusMessages[statusCode],\n });\n }\n }\n\n replyJson(responseJson: Json): void {\n this.logger_.logMethodArgs?.('replyJson', {responseJson});\n\n let responseString: string;\n try {\n responseString = JSON.stringify(responseJson);\n }\n catch (error) {\n this.logger_.error('replyJson', 'reply_json_stringify_failed', error, this.clientRequest.url.debugId);\n this.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n this.replyErrorResponse({\n ok: false,\n errorCode: 'reply_json_stringify_failed',\n errorMessage: 'Failed to stringify response JSON.',\n });\n return;\n }\n\n this.headers['content-type'] = 'application/json';\n this.reply(responseString);\n }\n\n reply(context: string | Buffer): void {\n this.logger_.logMethodArgs?.('reply', this.clientRequest.url.debugId);\n\n if (this.raw_.writableFinished && this.hasBeenSent_ === false) {\n // The response has already been sent by direct access to the server api.\n this.logger_.accident('reply', 'server_response_writable_finished_directly');\n this.hasBeenSent_ = true;\n }\n\n if (this.hasBeenSent_) {\n this.logger_.accident('reply', 'reply_already_sent', {\n url: this.clientRequest.url.debugId,\n replySent: this.hasBeenSent_,\n writableFinished: this.raw_.writableFinished,\n });\n return;\n }\n\n this.hasBeenSent_ = true;\n\n try {\n if (typeof context === 'string') {\n context = Buffer.from(context);\n }\n\n this.headers['content-length'] = context.byteLength;\n\n this.applyHeaders_();\n this.raw_.end(context, 'binary');\n }\n catch (error) {\n this.logger_.error('reply', 'server_response_error', error, this.clientRequest.url.debugId);\n this.hasBeenSent_ = false;\n }\n }\n}\n", "/**\n * Object representing standard HTTP methods.\n */\nexport const HttpMethods = {\n /**\n * GET: Requests a representation of the specified resource.\n */\n GET: 'GET',\n\n /**\n * HEAD: Asks for a response identical to that of a GET request, but without the response body.\n */\n HEAD: 'HEAD',\n\n /**\n * POST: Submits data to be processed (e.g., from an HTML form) to the identified resource.\n */\n POST: 'POST',\n\n /**\n * PUT: Uploads a representation of the specified URI.\n */\n PUT: 'PUT',\n\n /**\n * DELETE: Deletes the specified resource.\n */\n DELETE: 'DELETE',\n\n /**\n * CONNECT: Establishes a tunnel to the server identified by the target resource.\n */\n CONNECT: 'CONNECT',\n\n /**\n * OPTIONS: Describes the communication options for the target resource.\n */\n OPTIONS: 'OPTIONS',\n\n /**\n * TRACE: Performs a message loop-back test along the path to the target resource.\n */\n TRACE: 'TRACE',\n\n /**\n * PATCH: Applies partial modifications to a resource.\n */\n PATCH: 'PATCH'\n} as const;\n\n/**\n * Object representing standard HTTP status codes.\n */\nexport const HttpStatusCodes = {\n /**\n * 100 Continue: The server has received the request headers and the client should proceed to send the request body.\n */\n Info_100_Continue: 100,\n\n /**\n * 101 Switching Protocols: The server understands and is willing to comply with the clients request to switch protocols.\n */\n Info_101_Switching_Protocols: 101,\n\n /**\n * 102 Processing: The server has received and is processing the request, but no response is available yet.\n */\n Info_102_Processing: 102,\n\n /**\n * 103 Early Hints: The server is sending some response headers before the final HTTP message.\n */\n Info_103_Early_Hints: 103,\n\n /**\n * 200 OK: The request has succeeded.\n */\n Success_200_OK: 200,\n\n /**\n * 201 Created: The request has been fulfilled and resulted in a new resource being created.\n */\n Success_201_Created: 201,\n\n /**\n * 202 Accepted: The request has been accepted for processing, but the processing has not been completed.\n */\n Success_202_Accepted: 202,\n\n /**\n * 203 Non-Authoritative Information: The server is a transforming proxy that received a 200 OK\n * from the origin server but is returning a modified version of the origins response.\n */\n Success_203_Non_Authoritative_Information: 203,\n\n /**\n * 204 No Content: The server successfully processed the request and is not returning any content.\n */\n Success_204_No_Content: 204,\n\n /**\n * 205 Reset Content: The server successfully processed the request,\n * asks that the client reset its document view, and is not returning any content.\n */\n Success_205_Reset_Content: 205,\n\n /**\n * 206 Partial Content: The server is delivering only part of the resource due to a range header sent by the client.\n */\n Success_206_Partial_Content: 206,\n\n /**\n * 207 Multi-Status: The message body that follows is an XML message\n * and can contain a number of separate response codes, depending on how many sub-requests were made.\n */\n Success_207_Multi_Status: 207,\n\n /**\n * 208 Already Reported: The members of a DAV binding have already been enumerated\n * in a preceding part of the (multi-status) response, and are not being included again.\n */\n Success_208_Already_Reported: 208,\n\n /**\n * 226 IM Used: The server has fulfilled a request for the resource, and the response is a representation\n * of the result of one or more instance-manipulations applied to the current instance.\n */\n Success_226_IM_Used: 226,\n\n /**\n * 300 Multiple Choices: The request has more than one possible response.\n */\n Redirect_300_Multiple_Choices: 300,\n\n /**\n * 301 Moved Permanently: The URL of the requested resource has been changed permanently.\n */\n Redirect_301_Moved_Permanently: 301,\n\n /**\n * 302 Found: The URL of the requested resource has been changed temporarily.\n */\n Redirect_302_Found: 302,\n\n /**\n * 303 See Other: The response to the request can be found under another URI using a GET method.\n */\n Redirect_303_See_Other: 303,\n\n /**\n * 304 Not Modified: The resource has not been modified since the version specified\n * by the request headers If-Modified-Since or If-None-Match.\n */\n Redirect_304_Not_Modified: 304,\n\n /**\n * 305 Use Proxy: The requested resource is only available through a proxy, the address for which is provided in the response.\n */\n Redirect_305_Use_Proxy: 305,\n\n /**\n * 306 Switch Proxy: No longer used. Originally meant \"Subsequent requests should use the specified proxy.\"\n */\n Redirect_306_Switch_Proxy: 306,\n\n /**\n * 307 Temporary Redirect: The server sends this response to direct the client\n * to get the requested resource at another URI with the same method that was used in the prior request.\n */\n Redirect_307_Temporary_Redirect: 307,\n\n /**\n * 308 Permanent Redirect: This means that the resource is now permanently located at another URI,\n * specified by the Location: HTTP Response header.\n */\n Redirect_308_Permanent_Redirect: 308,\n\n /**\n * 400 Bad Request: The server cannot or will not process the request due to something that is perceived to be a client error.\n */\n Error_Client_400_Bad_Request: 400,\n\n /**\n * 401 Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource.\n */\n Error_Client_401_Unauthorized: 401,\n\n /**\n * 402 Payment Required: Reserved for future use.\n */\n Error_Client_402_Payment_Required: 402,\n\n /**\n * 403 Forbidden: The client does not have access rights to the content, so the server is refusing to give the requested resource.\n */\n Error_Client_403_Forbidden: 403,\n\n /**\n * 404 Not Found: The server can not find the requested resource.\n */\n Error_Client_404_Not_Found: 404,\n\n /**\n * 405 Method Not Allowed: The request method is known by the server but is not supported by the target resource.\n */\n Error_Client_405_Method_Not_Allowed: 405,\n\n /**\n * 406 Not Acceptable: The target resource does not have a current representation that would be acceptable\n * to the user agent, according to the proactive negotiation header fields received in the request,\n * and the server is unwilling to supply a default representation.\n */\n Error_Client_406_Not_Acceptable: 406,\n\n /**\n * 407 Proxy Authentication Required: Similar to 401 Unauthorized,\n * but it indicates that the client needs to authenticate itself in order to use a proxy.\n */\n Error_Client_407_Proxy_Authentication_Required: 407,\n\n /**\n * 408 Request Timeout: The server timed out waiting for the request.\n */\n Error_Client_408_Request_Timeout: 408,\n\n /**\n * 409 Conflict: The request could not be processed because of conflict in the request, such as an edit conflict.\n */\n Error_Client_409_Conflict: 409,\n\n /**\n * 410 Gone: The requested resource is no longer available and will not be available again.\n */\n Error_Client_410_Gone: 410,\n\n /**\n * 411 Length Required: The server refuses to accept the request without a defined Content-Length header.\n */\n Error_Client_411_Length_Required: 411,\n\n /**\n * 412 Precondition Failed: One or more conditions given in the request header fields evaluated to false when tested on the server.\n */\n Error_Client_412_Precondition_Failed: 412,\n\n /**\n * 413 Payload Too Large: The server is refusing to process a request because the request payload is larger\n * than the server is willing or able to process.\n */\n Error_Client_413_Payload_Too_Large: 413,\n\n /**\n * 414 URI Too Long: The server is refusing to service the request because the URI is longer than the server is willing to interpret.\n */\n Error_Client_414_URI_Too_Long: 414,\n\n /**\n * 415 Unsupported Media Type: The server is refusing to service the request\n * because the entity of the request is in a format not supported by the requested resource for the requested method.\n */\n Error_Client_415_Unsupported_Media_Type: 415,\n\n /**\n * 416 Range Not Satisfiable: The client has asked for a portion of the file, but the server cannot supply that portion.\n */\n Error_Client_416_Range_Not_Satisfiable: 416,\n\n /**\n * 417 Expectation Failed: The server cannot meet the requirements of the Expect request-header field.\n */\n Error_Client_417_Expectation_Failed: 417,\n\n /**\n * 421 Misdirected Request: The request was directed at a server that is not able to produce a response.\n */\n Error_Client_421_Misdirected_Request: 421,\n\n /**\n * 422 Unprocessable Entity: The request was well-formed but was unable to be followed due to semantic errors.\n */\n Error_Client_422_Unprocessable_Entity: 422,\n\n /**\n * 423 Locked: The resource that is being accessed is locked.\n */\n Error_Client_423_Locked: 423,\n\n /**\n * 424 Failed Dependency: The request failed due to a failure of a previous request.\n */\n Error_Client_424_Failed_Dependency: 424,\n\n /**\n * 425 Too Early: The server is unwilling to risk processing a request that might be replayed.\n */\n Error_Client_425_Too_Early: 425,\n\n /**\n * 426 Upgrade Required: The server refuses to perform the request using the current protocol\n * but might be willing to do so after the client upgrades to a different protocol.\n */\n Error_Client_426_Upgrade_Required: 426,\n\n /**\n * 428 Precondition Required: The origin server requires the request to be conditional.\n */\n Error_Client_428_Precondition_Required: 428,\n\n /**\n * 429 Too Many Requests: The user has sent too many requests in a given amount of time (\"rate limiting\").\n */\n Error_Client_429_Too_Many_Requests: 429,\n\n /**\n * 431 Request Header Fields Too Large: The server is unwilling to process the request because its header fields are too large.\n */\n Error_Client_431_Request_Header_Fields_Too_Large: 431,\n\n /**\n * 451 Unavailable For Legal Reasons: The user requests an illegal resource, such as a web page censored by a government.\n */\n Error_Client_451_Unavailable_For_Legal_Reasons: 451,\n\n /**\n * 500 Internal Server Error: A generic error message, given when no more specific message is suitable.\n */\n Error_Server_500_Internal_Server_Error: 500,\n\n /**\n * 501 Not Implemented: The server either does not recognize the request method, or it lacks the ability to fulfill the request.\n */\n Error_Server_501_Not_Implemented: 501,\n\n /**\n * 502 Bad Gateway: The server was acting as a gateway or proxy and received an invalid response from the upstream server.\n */\n Error_Server_502_Bad_Gateway: 502,\n\n /**\n * 503 Service Unavailable: The server is currently unavailable (because it is overloaded or down for maintenance).\n */\n Error_Server_503_Service_Unavailable: 503,\n\n /**\n * 504 Gateway Timeout: The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.\n */\n Error_Server_504_Gateway_Timeout: 504,\n\n /**\n * 505 HTTP Version Not Supported: The server does not support the HTTP protocol version used in the request.\n */\n Error_Server_505_HTTP_Version_Not_Supported: 505,\n\n /**\n * 506 Variant Also Negotiates: Transparent content negotiation for the request results in a circular reference.\n */\n Error_Server_506_Variant_Also_Negotiates: 506,\n\n /**\n * 507 Insufficient Storage: The server is unable to store the representation needed to complete the request.\n */\n Error_Server_507_Insufficient_Storage: 507,\n\n /**\n * 508 Loop Detected: The server detected an infinite loop while processing the request.\n */\n Error_Server_508_Loop_Detected: 508,\n\n /**\n * 510 Not Extended: Further extensions to the request are required for the server to fulfill it.\n */\n Error_Server_510_Not_Extended: 510,\n\n /**\n * 511 Network Authentication Required: The client needs to authenticate to gain network access.\n */\n Error_Server_511_Network_Authentication_Required: 511\n} as const;\n\nexport const HttpStatusMessages = {\n 100: 'Continue',\n 101: 'Switching Protocols',\n 102: 'Processing',\n 103: 'Early Hints',\n 200: 'OK',\n 201: 'Created',\n 202: 'Accepted',\n 203: 'Non-Authoritative Information',\n 204: 'No Content',\n 205: 'Reset Content',\n 206: 'Partial Content',\n 207: 'Multi-Status',\n 208: 'Already Reported',\n 226: 'IM Used',\n 300: 'Multiple Choices',\n 301: 'Moved Permanently',\n 302: 'Found',\n 303: 'See Other',\n 304: 'Not Modified',\n 305: 'Use Proxy',\n 307: 'Temporary Redirect',\n 308: 'Permanent Redirect',\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Failed',\n 413: 'Payload Too Large',\n 414: 'URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: 'I\\'m a Teapot',\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 425: 'Too Early',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 451: 'Unavailable For Legal Reasons',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 506: 'Variant Also Negotiates',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 509: 'Bandwidth Limit Exceeded',\n 510: 'Not Extended',\n 511: 'Network Authentication Required',\n};\n\nexport type HttpStatusCode = keyof typeof HttpStatusMessages;\n", "import {URL} from 'node:url';\n\nimport type {HttpMethod, NativeClientRequest} from './type.js';\n\nexport class NanotronUrl extends URL {\n protected static versionPattern_ = new RegExp('^/v[0-9]+/');\n\n readonly method: HttpMethod;\n readonly debugId: string;\n\n constructor(clientRequest: NativeClientRequest, prefix: `/${string}/` | '/') {\n let url = clientRequest.url ?? '';\n if (prefix !== '/' && url.indexOf(prefix) === 0) {\n url = url.slice(prefix.length - 1); // include `/`\n }\n url = url.replace(NanotronUrl.versionPattern_, '/');\n\n super(url, 'http://hostname/');\n\n this.method = (clientRequest.method ?? 'GET').toUpperCase() as HttpMethod;\n\n this.debugId = `[${this.method}]${this.pathname}`;\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAA2B;AAE3B,IAAAA,kBAA0C;;;ACF1C,IAAAC,kBAA2B;;;ACA3B,qBAA2B;;;ACGpB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA,EAIzB,KAAK;AAAA;AAAA;AAAA;AAAA,EAKL,MAAM;AAAA;AAAA;AAAA;AAAA,EAKN,MAAM;AAAA;AAAA;AAAA;AAAA,EAKN,KAAK;AAAA;AAAA;AAAA;AAAA,EAKL,QAAQ;AAAA;AAAA;AAAA;AAAA,EAKR,SAAS;AAAA;AAAA;AAAA;AAAA,EAKT,SAAS;AAAA;AAAA;AAAA;AAAA,EAKT,OAAO;AAAA;AAAA;AAAA;AAAA,EAKP,OAAO;AACT;AAKO,IAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAI7B,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAKnB,8BAA8B;AAAA;AAAA;AAAA;AAAA,EAK9B,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAKrB,sBAAsB;AAAA;AAAA;AAAA;AAAA,EAKtB,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAKhB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A,EAChB,QAAQ;AAAA,EACR,WAAW;AAAA;AACb;AAXK,IAAM,oBAAN;",
4
+ "sourcesContent": ["export * from './api-server.js';\nexport * from './type.js';\nexport * from './const.js';\n\nexport type {NanotronClientRequest} from './api-client-request.js';\nexport type {NanotronServerResponse} from './api-server-response.js';\nexport type {NanotronUrl} from './url.js';\n", "import {createServer} from 'node:http';\n\nimport {createLogger, packageTracer} from '@alwatr/nanolib';\n\nimport {NanotronClientRequest} from './api-client-request.js';\nimport {HttpStatusCodes, HttpStatusMessages} from './const.js';\nimport {NanotronUrl} from './url.js';\n\nimport type {DefineRouteOption, MatchType, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {Duplex} from 'node:stream';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Configuration options for the NanotronApiServer.\n */\nexport interface NanotronApiServerConfig {\n /**\n * The port number to listen on.\n *\n * @default 80\n */\n port?: number;\n\n /**\n * The hostname to listen on.\n *\n * @default '0.0.0.0'\n */\n host?: string;\n\n /**\n * Sets the timeout (ms) for receiving the entire request from the client.\n *\n * @default 10_000 ms\n */\n requestTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * This should be bigger than `keepAliveTimeout + your server's expected response time`.\n *\n * @default 130_000 ms\n */\n headersTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * @default 120_000 ms\n */\n keepAliveTimeout?: number;\n\n /**\n * Add /health route.\n *\n * @default true\n */\n healthRoute?: boolean;\n\n /**\n * Add OPTIONS route for preflight requests to allow access origins.\n *\n * @default {enable: false, origin: '*', methods: '*', headers: '*', maxAge: 86_400}\n */\n crossOrigin?: {\n enable: boolean;\n origin: string;\n methods: string;\n headers: string;\n maxAge: string | number;\n },\n\n /**\n * A prefix to be added to the beginning of the `url` of all defined routes.\n *\n * @default '/api/'\n */\n prefix?: `/${string}/` | '/';\n\n /**\n * The maximum size of the request body in bytes.\n *\n * @default `1_048_576` (1MiB)\n */\n bodyLimit?: number;\n}\n\nexport class NanotronApiServer {\n protected static readonly defaultConfig_: Readonly<Required<NanotronApiServerConfig>> = {\n host: '0.0.0.0',\n port: 80,\n requestTimeout: 10_000,\n headersTimeout: 130_000,\n keepAliveTimeout: 120_000,\n healthRoute: true,\n crossOrigin: {\n enable: false,\n origin: '*',\n methods: '*',\n headers: '*',\n maxAge: 86_400, // 24h\n },\n prefix: '/api/',\n bodyLimit: 1_048_576, // 1MiB\n };\n\n readonly config_: Required<NanotronApiServerConfig>;\n protected readonly logger_;\n\n readonly httpServer;\n\n protected readonly routeHandlerList__: Record<MatchType, DictionaryOpt<DictionaryOpt<Required<DefineRouteOption>>>>;\n\n constructor(config?: Partial<NanotronApiServerConfig>) {\n // Merge the config with the default config.\n this.config_ = {\n ...NanotronApiServer.defaultConfig_,\n ...config,\n };\n\n // Create logger.\n this.logger_ = createLogger('nt-api-server' + (this.config_.port !== 80 ? ':' + this.config_.port : ''));\n this.logger_.logMethodArgs?.('new', {config: this.config_});\n\n // Bind methods.\n this.handleClientRequest_ = this.handleClientRequest_.bind(this);\n this.handleServerError_ = this.handleServerError_.bind(this);\n this.handleClientError_ = this.handleClientError_.bind(this);\n\n // Initialize route handler list.\n this.routeHandlerList__ = {\n exact: {},\n startsWith: {},\n };\n\n // Create the HTTP server.\n this.httpServer = createServer(\n {\n keepAlive: true,\n keepAliveInitialDelay: 0,\n noDelay: true,\n },\n this.handleClientRequest_,\n );\n\n // Configure the server.\n this.httpServer.requestTimeout = this.config_.requestTimeout;\n this.httpServer.keepAliveTimeout = this.config_.keepAliveTimeout;\n this.httpServer.headersTimeout = this.config_.headersTimeout;\n\n // Start the server.\n this.httpServer.listen(this.config_.port, this.config_.host, () => {\n this.logger_.logOther?.(`listening on ${this.config_.host}:${this.config_.port}`);\n });\n\n // Handle server errors.\n this.httpServer.on('error', this.handleServerError_);\n this.httpServer.on('clientError', this.handleClientError_);\n\n this.defineCorsRoute_();\n\n if (this.config_.healthRoute) {\n this.defineHealthRoute_();\n }\n }\n\n close(): void {\n this.logger_.logMethod?.('close');\n this.httpServer.close();\n }\n\n protected getRouteOption_(url: NanotronUrl): Required<DefineRouteOption> | null {\n this.logger_.logMethod?.('getRouteOption_');\n\n if (\n Object.hasOwn(this.routeHandlerList__.exact, url.method) &&\n Object.hasOwn(this.routeHandlerList__.exact[url.method]!, url.pathname)\n ) {\n return this.routeHandlerList__.exact[url.method]![url.pathname]!;\n }\n\n if (Object.hasOwn(this.routeHandlerList__.startsWith, url.method)) {\n const routeList = this.routeHandlerList__.startsWith[url.method];\n for (const pathname in routeList) {\n if (pathname.indexOf(url.pathname) === 0) {\n return routeList[pathname]!;\n }\n }\n }\n\n this.logger_.incident?.('getRouteOption_', 'route_not_found', {method: url.method, url: url.pathname});\n return null;\n }\n\n protected setRouteOption_(option: Required<DefineRouteOption>): void {\n this.logger_.logMethodArgs?.('setRouteOption_', option);\n\n const routeHandlerList = this.routeHandlerList__[option.matchType];\n\n routeHandlerList[option.method] ??= {};\n\n if (Object.hasOwn(routeHandlerList[option.method]!, option.url)) {\n this.logger_.error('defineRoute', 'route_already_exists', option);\n throw new Error('route_already_exists');\n }\n\n routeHandlerList[option.method]![option.url] = option;\n }\n\n defineRoute<TSharedMeta extends DictionaryOpt = DictionaryOpt>(option: DefineRouteOption<TSharedMeta>): void {\n const option_: Required<DefineRouteOption<TSharedMeta>> = {\n matchType: 'exact',\n preHandlers: [],\n postHandlers: [],\n bodyLimit: this.config_.bodyLimit,\n crossOrigin: this.config_.crossOrigin,\n ...option,\n };\n this.logger_.logMethodArgs?.('defineRoute', option_);\n this.setRouteOption_(option_ as Required<DefineRouteOption>);\n }\n\n protected handleServerError_(error: NodeJS.ErrnoException): void {\n if (error.code === 'EADDRINUSE') {\n this.logger_.error('handleServerError_', 'address_in_use', error);\n }\n else {\n this.logger_.error('handleServerError_', 'http_server_error', error);\n }\n }\n\n protected handleClientError_(err: NodeJS.ErrnoException, socket: Duplex): void {\n this.logger_.accident('handleClientError_', 'http_server_client_error', {\n errCode: err.code,\n errMessage: err.message,\n });\n\n const errorCode = err.code?.toLowerCase() ?? `error_${HttpStatusCodes.Error_Client_400_Bad_Request}`;\n const errorMessage = err.message ?? HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request];\n const errorResponse = `{\"ok\":false,\"errorCode\":\"${errorCode}\",\"errorMessage\":\"${errorMessage}\"}`;\n\n const responseHeaders = [\n `HTTP/1.1 ${HttpStatusCodes.Error_Client_400_Bad_Request} ${HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request]}`,\n 'content-type: application/json',\n `content-length: ${Buffer.byteLength(errorResponse)}`,\n '\\r\\n',\n ].join('\\r\\n');\n\n socket.end(responseHeaders + errorResponse);\n }\n\n protected async handleClientRequest_(\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n ): Promise<void> {\n this.logger_.logMethod?.('handleClientRequest_');\n\n if (nativeClientRequest.url === undefined) {\n this.logger_.accident('handleClientRequest_', 'http_server_url_undefined');\n return;\n }\n\n const url = new NanotronUrl(nativeClientRequest, this.config_.prefix);\n\n const routeOption = this.getRouteOption_(url);\n\n const connection = new NanotronClientRequest(url, nativeClientRequest, nativeServerResponse, routeOption);\n\n if (routeOption === null) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Client_404_Not_Found;\n connection.serverResponse.replyError();\n return;\n }\n\n try {\n for (const handler of routeOption.preHandlers) {\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n if (connection.terminatedHandlers === true) return; // must check after each pre-handler.\n }\n\n await routeOption.handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n\n for (const handler of routeOption.postHandlers) {\n if (connection.terminatedHandlers === true) return; // must check before each post-handler.\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n }\n }\n catch (error) {\n this.logger_.error('handleClientRequest_', 'route_handler_error', error, url.debugId);\n\n if (connection.serverResponse.statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n }\n connection.serverResponse.replyError(error);\n }\n\n // TODO: handled open remained connections.\n }\n\n protected defineHealthRoute_(): void {\n this.logger_.logMethod?.('defineHealthRoute_');\n\n this.defineRoute({\n method: 'GET',\n url: '/health',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.statusCode = HttpStatusCodes.Success_200_OK;\n res.setHeader('server', 'Alwatr Nanotron');\n res.setHeader('content-type', 'application/json');\n res.end('{\"ok\":true}');\n },\n });\n }\n\n protected defineCorsRoute_(): void {\n this.logger_.logMethod?.('defineCorsRoute_');\n const crossOrigin = this.config_.crossOrigin;\n if (crossOrigin?.enable !== true) return;\n this.defineRoute({\n method: 'OPTIONS',\n matchType: 'startsWith',\n url: '/',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.writeHead(HttpStatusCodes.Success_204_No_Content, {\n 'access-control-allow-origin': crossOrigin.origin,\n 'access-control-allow-methods': crossOrigin.methods,\n 'access-control-allow-headers': crossOrigin.headers,\n 'access-control-max-age': crossOrigin.maxAge + '',\n 'content-length': 0,\n });\n res.end();\n },\n });\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {NanotronServerResponse} from './api-server-response.js';\nimport {HttpStatusCodes} from './const.js';\n\nimport type {DefineRouteOption, HttpRequestHeaders, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {NanotronUrl} from './url.js';\n\nexport class NanotronClientRequest<TSharedMeta extends DictionaryOpt = DictionaryOpt> {\n readonly url: NanotronUrl;\n\n readonly serverResponse: NanotronServerResponse;\n\n readonly routeOption: Required<DefineRouteOption> | null;\n\n /**\n * A flag to indicate if the running handlers queue has been terminated.\n * This can occur due to an error being thrown or by explicitly calling the `replyError` method.\n *\n * When `terminatedHandlers` is set to `true`, it signifies that the execution of the current\n * sequence of handlers (including pre, main, and post handlers) has been halted and no further\n * handlers in the queue will be executed.\n *\n * Usage:\n * - Check this flag to determine if the handlers queue has been interrupted.\n * - Set this flag to `true` to manually stop the execution of subsequent handlers.\n */\n terminatedHandlers?: true;\n\n readonly sharedMeta: TSharedMeta = {} as TSharedMeta;\n\n readonly raw_: NativeClientRequest;\n\n protected readonly logger_;\n\n readonly remoteAddress: string | null;\n\n get headers(): HttpRequestHeaders {\n return this.raw_.headers;\n }\n\n private queryParams__?: DictionaryOpt<string>;\n get queryParams(): DictionaryOpt<string> {\n if (this.queryParams__ === undefined) {\n this.queryParams__ = {};\n for (const [key, value] of this.url.searchParams.entries()) {\n this.queryParams__[key] = value;\n }\n }\n return this.queryParams__;\n }\n\n constructor(\n url: NanotronUrl,\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n routeOption: Required<DefineRouteOption> | null,\n ) {\n // Store public properties.\n this.raw_ = nativeClientRequest;\n this.url = url;\n this.routeOption = routeOption;\n\n // Get and store remote address.\n this.remoteAddress = this.getRemoteAddress__();\n\n // Create logger.\n this.logger_ = createLogger(`nt-client-request(${this.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', url.debugId);\n\n // Create server response.\n this.serverResponse = new NanotronServerResponse(this, nativeServerResponse);\n }\n\n getBodyRaw(): Promise<Buffer> {\n return new Promise((resolve, reject) => {\n // method must be POST or PUT or PATCH\n const method = this.url.method;\n if (!(method === 'POST' || method === 'PUT' || method === 'PATCH')) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_405_Method_Not_Allowed;\n return reject(new Error('body_not_allowed'));\n }\n\n const contentLength = +this.raw_.headers['content-length']!;\n\n if (Number.isNaN(contentLength) || contentLength === 0) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_411_Length_Required;\n return reject(new Error('body_length_required'));\n }\n\n if (contentLength > this.routeOption!.bodyLimit) {\n // TODO: routeOption when null?!\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const dataChunks: Uint8Array[] = [];\n let receivedLength = 0;\n\n const onData = (chunk: Uint8Array) => {\n receivedLength += chunk.length;\n dataChunks.push(chunk);\n\n if (receivedLength > this.routeOption!.bodyLimit) {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n dataChunks.length = 0; // free memory\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n };\n\n const onEnd = (err?: Error) => {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n\n if (err !== undefined) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_400_Bad_Request;\n return reject(err);\n }\n\n if (receivedLength !== contentLength) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const body = Buffer.concat(dataChunks);\n\n resolve(body);\n };\n\n this.raw_.on('data', onData);\n this.raw_.on('end', onEnd);\n this.raw_.on('error', onEnd);\n this.raw_.resume();\n });\n }\n\n private getRemoteAddress__(): string | null {\n return this.raw_.headers['x-forwarded-for']?.split(',').pop()?.trim() || this.raw_.socket.remoteAddress || null;\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {type HttpStatusCode, HttpStatusCodes, HttpStatusMessages} from './const.js';\n\nimport type {NanotronClientRequest} from './api-client-request.js';\nimport type {HttpResponseHeaders, ErrorResponse, NativeServerResponse} from './type.js';\n\n/**\n * Configuration options for the Nanotron Api Server Response.\n */\nexport interface NanotronServerResponseConfig {\n clientRequest: NanotronClientRequest;\n}\n\nexport class NanotronServerResponse {\n readonly clientRequest: NanotronClientRequest;\n\n readonly raw_: NativeServerResponse;\n\n readonly headers: HttpResponseHeaders;\n\n protected readonly logger_;\n\n protected hasBeenSent_ = false;\n get hasBeenSent(): boolean {\n return this.hasBeenSent_;\n }\n\n constructor(nanotronClientRequest: NanotronClientRequest, nativeServerResponse: NativeServerResponse) {\n // Store public properties.\n this.clientRequest = nanotronClientRequest;\n this.raw_ = nativeServerResponse;\n\n // Create logger.\n this.logger_ = createLogger(`nt-server-response(${this.clientRequest.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', this.clientRequest.url.debugId);\n\n // Set default reply headers.\n this.headers = {\n server: 'Alwatr Nanotron',\n 'content-type': 'text/plain charset=UTF-8',\n };\n\n const crossOrigin = this.clientRequest.routeOption?.crossOrigin;\n if (crossOrigin?.enable === true) {\n this.headers['access-control-allow-origin'] = crossOrigin.origin;\n this.headers['access-control-allow-methods'] = crossOrigin.methods;\n this.headers['access-control-allow-headers'] = crossOrigin.headers;\n this.headers['access-control-max-age'] = crossOrigin.maxAge;\n }\n }\n\n get statusCode(): HttpStatusCode {\n return this.raw_.statusCode as HttpStatusCode;\n }\n\n set statusCode(value: HttpStatusCode) {\n this.raw_.statusCode = value;\n }\n\n protected applyHeaders_() {\n this.logger_.logMethodArgs?.('applyHeaders_', this.headers);\n for (const key in this.headers) {\n this.raw_.setHeader(key, this.headers[key as Lowercase<string>]!);\n }\n }\n\n replyErrorResponse(errorResponse: ErrorResponse): void {\n this.logger_.logMethod?.('replyErrorResponse');\n this.clientRequest.terminatedHandlers = true;\n this.headers['content-type'] = 'application/json';\n let meta = '';\n if (errorResponse.meta !== undefined) {\n const metaType = typeof errorResponse.meta;\n if (\n metaType === 'string' ||\n metaType === 'number' ||\n metaType === 'boolean' ||\n errorResponse.meta === null) {\n meta = `,\"meta\":\"${errorResponse.meta}\"`;\n }\n else if (metaType === 'object') {\n meta = `,\"meta\":${JSON.stringify(errorResponse.meta)}`;\n }\n }\n const responseString = `{\"ok\":false,\"errorCode\":\"${errorResponse.errorCode}\",\"errorMessage\":\"${errorResponse.errorMessage}\"${meta}}`;\n this.reply(responseString);\n }\n\n replyError(error?: Error | string | Json | unknown): void {\n this.logger_.logMethodArgs?.('replyError', {error});\n\n this.clientRequest.terminatedHandlers = true;\n let statusCode = this.statusCode;\n\n if (statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n this.statusCode = statusCode = 500;\n }\n\n if (error instanceof Error) {\n this.replyErrorResponse({\n ok: false,\n errorCode: (error.name === 'Error' ? 'error_' + statusCode : (error.name + '').toLowerCase()) as Lowercase<string>,\n errorMessage: error.message,\n });\n }\n else if (typeof error === 'string') {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: error,\n });\n }\n else if (typeof error === 'object' && error !== null) {\n this.replyJson(error as Json);\n }\n else {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: HttpStatusMessages[statusCode],\n });\n }\n }\n\n replyJson(responseJson: Json): void {\n this.logger_.logMethodArgs?.('replyJson', {responseJson});\n\n let responseString: string;\n try {\n responseString = JSON.stringify(responseJson);\n }\n catch (error) {\n this.logger_.error('replyJson', 'reply_json_stringify_failed', error, this.clientRequest.url.debugId);\n this.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n this.replyErrorResponse({\n ok: false,\n errorCode: 'reply_json_stringify_failed',\n errorMessage: 'Failed to stringify response JSON.',\n });\n return;\n }\n\n this.headers['content-type'] = 'application/json';\n this.reply(responseString);\n }\n\n reply(context: string | Buffer): void {\n this.logger_.logMethodArgs?.('reply', this.clientRequest.url.debugId);\n\n if (this.raw_.writableFinished && this.hasBeenSent_ === false) {\n // The response has already been sent by direct access to the server api.\n this.logger_.accident('reply', 'server_response_writable_finished_directly');\n this.hasBeenSent_ = true;\n }\n\n if (this.hasBeenSent_) {\n this.logger_.accident('reply', 'reply_already_sent', {\n url: this.clientRequest.url.debugId,\n replySent: this.hasBeenSent_,\n writableFinished: this.raw_.writableFinished,\n });\n return;\n }\n\n this.hasBeenSent_ = true;\n\n try {\n if (typeof context === 'string') {\n context = Buffer.from(context);\n }\n\n this.headers['content-length'] = context.byteLength;\n\n this.applyHeaders_();\n this.raw_.end(context, 'binary');\n }\n catch (error) {\n this.logger_.error('reply', 'server_response_error', error, this.clientRequest.url.debugId);\n this.hasBeenSent_ = false;\n }\n }\n}\n", "/**\n * Object representing standard HTTP methods.\n */\nexport const HttpMethods = {\n /**\n * GET: Requests a representation of the specified resource.\n */\n GET: 'GET',\n\n /**\n * HEAD: Asks for a response identical to that of a GET request, but without the response body.\n */\n HEAD: 'HEAD',\n\n /**\n * POST: Submits data to be processed (e.g., from an HTML form) to the identified resource.\n */\n POST: 'POST',\n\n /**\n * PUT: Uploads a representation of the specified URI.\n */\n PUT: 'PUT',\n\n /**\n * DELETE: Deletes the specified resource.\n */\n DELETE: 'DELETE',\n\n /**\n * CONNECT: Establishes a tunnel to the server identified by the target resource.\n */\n CONNECT: 'CONNECT',\n\n /**\n * OPTIONS: Describes the communication options for the target resource.\n */\n OPTIONS: 'OPTIONS',\n\n /**\n * TRACE: Performs a message loop-back test along the path to the target resource.\n */\n TRACE: 'TRACE',\n\n /**\n * PATCH: Applies partial modifications to a resource.\n */\n PATCH: 'PATCH'\n} as const;\n\n/**\n * Object representing standard HTTP status codes.\n */\nexport const HttpStatusCodes = {\n /**\n * 100 Continue: The server has received the request headers and the client should proceed to send the request body.\n */\n Info_100_Continue: 100,\n\n /**\n * 101 Switching Protocols: The server understands and is willing to comply with the clients request to switch protocols.\n */\n Info_101_Switching_Protocols: 101,\n\n /**\n * 102 Processing: The server has received and is processing the request, but no response is available yet.\n */\n Info_102_Processing: 102,\n\n /**\n * 103 Early Hints: The server is sending some response headers before the final HTTP message.\n */\n Info_103_Early_Hints: 103,\n\n /**\n * 200 OK: The request has succeeded.\n */\n Success_200_OK: 200,\n\n /**\n * 201 Created: The request has been fulfilled and resulted in a new resource being created.\n */\n Success_201_Created: 201,\n\n /**\n * 202 Accepted: The request has been accepted for processing, but the processing has not been completed.\n */\n Success_202_Accepted: 202,\n\n /**\n * 203 Non-Authoritative Information: The server is a transforming proxy that received a 200 OK\n * from the origin server but is returning a modified version of the origins response.\n */\n Success_203_Non_Authoritative_Information: 203,\n\n /**\n * 204 No Content: The server successfully processed the request and is not returning any content.\n */\n Success_204_No_Content: 204,\n\n /**\n * 205 Reset Content: The server successfully processed the request,\n * asks that the client reset its document view, and is not returning any content.\n */\n Success_205_Reset_Content: 205,\n\n /**\n * 206 Partial Content: The server is delivering only part of the resource due to a range header sent by the client.\n */\n Success_206_Partial_Content: 206,\n\n /**\n * 207 Multi-Status: The message body that follows is an XML message\n * and can contain a number of separate response codes, depending on how many sub-requests were made.\n */\n Success_207_Multi_Status: 207,\n\n /**\n * 208 Already Reported: The members of a DAV binding have already been enumerated\n * in a preceding part of the (multi-status) response, and are not being included again.\n */\n Success_208_Already_Reported: 208,\n\n /**\n * 226 IM Used: The server has fulfilled a request for the resource, and the response is a representation\n * of the result of one or more instance-manipulations applied to the current instance.\n */\n Success_226_IM_Used: 226,\n\n /**\n * 300 Multiple Choices: The request has more than one possible response.\n */\n Redirect_300_Multiple_Choices: 300,\n\n /**\n * 301 Moved Permanently: The URL of the requested resource has been changed permanently.\n */\n Redirect_301_Moved_Permanently: 301,\n\n /**\n * 302 Found: The URL of the requested resource has been changed temporarily.\n */\n Redirect_302_Found: 302,\n\n /**\n * 303 See Other: The response to the request can be found under another URI using a GET method.\n */\n Redirect_303_See_Other: 303,\n\n /**\n * 304 Not Modified: The resource has not been modified since the version specified\n * by the request headers If-Modified-Since or If-None-Match.\n */\n Redirect_304_Not_Modified: 304,\n\n /**\n * 305 Use Proxy: The requested resource is only available through a proxy, the address for which is provided in the response.\n */\n Redirect_305_Use_Proxy: 305,\n\n /**\n * 306 Switch Proxy: No longer used. Originally meant \"Subsequent requests should use the specified proxy.\"\n */\n Redirect_306_Switch_Proxy: 306,\n\n /**\n * 307 Temporary Redirect: The server sends this response to direct the client\n * to get the requested resource at another URI with the same method that was used in the prior request.\n */\n Redirect_307_Temporary_Redirect: 307,\n\n /**\n * 308 Permanent Redirect: This means that the resource is now permanently located at another URI,\n * specified by the Location: HTTP Response header.\n */\n Redirect_308_Permanent_Redirect: 308,\n\n /**\n * 400 Bad Request: The server cannot or will not process the request due to something that is perceived to be a client error.\n */\n Error_Client_400_Bad_Request: 400,\n\n /**\n * 401 Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource.\n */\n Error_Client_401_Unauthorized: 401,\n\n /**\n * 402 Payment Required: Reserved for future use.\n */\n Error_Client_402_Payment_Required: 402,\n\n /**\n * 403 Forbidden: The client does not have access rights to the content, so the server is refusing to give the requested resource.\n */\n Error_Client_403_Forbidden: 403,\n\n /**\n * 404 Not Found: The server can not find the requested resource.\n */\n Error_Client_404_Not_Found: 404,\n\n /**\n * 405 Method Not Allowed: The request method is known by the server but is not supported by the target resource.\n */\n Error_Client_405_Method_Not_Allowed: 405,\n\n /**\n * 406 Not Acceptable: The target resource does not have a current representation that would be acceptable\n * to the user agent, according to the proactive negotiation header fields received in the request,\n * and the server is unwilling to supply a default representation.\n */\n Error_Client_406_Not_Acceptable: 406,\n\n /**\n * 407 Proxy Authentication Required: Similar to 401 Unauthorized,\n * but it indicates that the client needs to authenticate itself in order to use a proxy.\n */\n Error_Client_407_Proxy_Authentication_Required: 407,\n\n /**\n * 408 Request Timeout: The server timed out waiting for the request.\n */\n Error_Client_408_Request_Timeout: 408,\n\n /**\n * 409 Conflict: The request could not be processed because of conflict in the request, such as an edit conflict.\n */\n Error_Client_409_Conflict: 409,\n\n /**\n * 410 Gone: The requested resource is no longer available and will not be available again.\n */\n Error_Client_410_Gone: 410,\n\n /**\n * 411 Length Required: The server refuses to accept the request without a defined Content-Length header.\n */\n Error_Client_411_Length_Required: 411,\n\n /**\n * 412 Precondition Failed: One or more conditions given in the request header fields evaluated to false when tested on the server.\n */\n Error_Client_412_Precondition_Failed: 412,\n\n /**\n * 413 Payload Too Large: The server is refusing to process a request because the request payload is larger\n * than the server is willing or able to process.\n */\n Error_Client_413_Payload_Too_Large: 413,\n\n /**\n * 414 URI Too Long: The server is refusing to service the request because the URI is longer than the server is willing to interpret.\n */\n Error_Client_414_URI_Too_Long: 414,\n\n /**\n * 415 Unsupported Media Type: The server is refusing to service the request\n * because the entity of the request is in a format not supported by the requested resource for the requested method.\n */\n Error_Client_415_Unsupported_Media_Type: 415,\n\n /**\n * 416 Range Not Satisfiable: The client has asked for a portion of the file, but the server cannot supply that portion.\n */\n Error_Client_416_Range_Not_Satisfiable: 416,\n\n /**\n * 417 Expectation Failed: The server cannot meet the requirements of the Expect request-header field.\n */\n Error_Client_417_Expectation_Failed: 417,\n\n /**\n * 421 Misdirected Request: The request was directed at a server that is not able to produce a response.\n */\n Error_Client_421_Misdirected_Request: 421,\n\n /**\n * 422 Unprocessable Entity: The request was well-formed but was unable to be followed due to semantic errors.\n */\n Error_Client_422_Unprocessable_Entity: 422,\n\n /**\n * 423 Locked: The resource that is being accessed is locked.\n */\n Error_Client_423_Locked: 423,\n\n /**\n * 424 Failed Dependency: The request failed due to a failure of a previous request.\n */\n Error_Client_424_Failed_Dependency: 424,\n\n /**\n * 425 Too Early: The server is unwilling to risk processing a request that might be replayed.\n */\n Error_Client_425_Too_Early: 425,\n\n /**\n * 426 Upgrade Required: The server refuses to perform the request using the current protocol\n * but might be willing to do so after the client upgrades to a different protocol.\n */\n Error_Client_426_Upgrade_Required: 426,\n\n /**\n * 428 Precondition Required: The origin server requires the request to be conditional.\n */\n Error_Client_428_Precondition_Required: 428,\n\n /**\n * 429 Too Many Requests: The user has sent too many requests in a given amount of time (\"rate limiting\").\n */\n Error_Client_429_Too_Many_Requests: 429,\n\n /**\n * 431 Request Header Fields Too Large: The server is unwilling to process the request because its header fields are too large.\n */\n Error_Client_431_Request_Header_Fields_Too_Large: 431,\n\n /**\n * 451 Unavailable For Legal Reasons: The user requests an illegal resource, such as a web page censored by a government.\n */\n Error_Client_451_Unavailable_For_Legal_Reasons: 451,\n\n /**\n * 500 Internal Server Error: A generic error message, given when no more specific message is suitable.\n */\n Error_Server_500_Internal_Server_Error: 500,\n\n /**\n * 501 Not Implemented: The server either does not recognize the request method, or it lacks the ability to fulfill the request.\n */\n Error_Server_501_Not_Implemented: 501,\n\n /**\n * 502 Bad Gateway: The server was acting as a gateway or proxy and received an invalid response from the upstream server.\n */\n Error_Server_502_Bad_Gateway: 502,\n\n /**\n * 503 Service Unavailable: The server is currently unavailable (because it is overloaded or down for maintenance).\n */\n Error_Server_503_Service_Unavailable: 503,\n\n /**\n * 504 Gateway Timeout: The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.\n */\n Error_Server_504_Gateway_Timeout: 504,\n\n /**\n * 505 HTTP Version Not Supported: The server does not support the HTTP protocol version used in the request.\n */\n Error_Server_505_HTTP_Version_Not_Supported: 505,\n\n /**\n * 506 Variant Also Negotiates: Transparent content negotiation for the request results in a circular reference.\n */\n Error_Server_506_Variant_Also_Negotiates: 506,\n\n /**\n * 507 Insufficient Storage: The server is unable to store the representation needed to complete the request.\n */\n Error_Server_507_Insufficient_Storage: 507,\n\n /**\n * 508 Loop Detected: The server detected an infinite loop while processing the request.\n */\n Error_Server_508_Loop_Detected: 508,\n\n /**\n * 510 Not Extended: Further extensions to the request are required for the server to fulfill it.\n */\n Error_Server_510_Not_Extended: 510,\n\n /**\n * 511 Network Authentication Required: The client needs to authenticate to gain network access.\n */\n Error_Server_511_Network_Authentication_Required: 511\n} as const;\n\nexport const HttpStatusMessages = {\n 100: 'Continue',\n 101: 'Switching Protocols',\n 102: 'Processing',\n 103: 'Early Hints',\n 200: 'OK',\n 201: 'Created',\n 202: 'Accepted',\n 203: 'Non-Authoritative Information',\n 204: 'No Content',\n 205: 'Reset Content',\n 206: 'Partial Content',\n 207: 'Multi-Status',\n 208: 'Already Reported',\n 226: 'IM Used',\n 300: 'Multiple Choices',\n 301: 'Moved Permanently',\n 302: 'Found',\n 303: 'See Other',\n 304: 'Not Modified',\n 305: 'Use Proxy',\n 307: 'Temporary Redirect',\n 308: 'Permanent Redirect',\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Failed',\n 413: 'Payload Too Large',\n 414: 'URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: 'I\\'m a Teapot',\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 425: 'Too Early',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 451: 'Unavailable For Legal Reasons',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 506: 'Variant Also Negotiates',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 509: 'Bandwidth Limit Exceeded',\n 510: 'Not Extended',\n 511: 'Network Authentication Required',\n};\n\nexport type HttpStatusCode = keyof typeof HttpStatusMessages;\n", "import {URL} from 'node:url';\n\nimport type {HttpMethod, NativeClientRequest} from './type.js';\n\nexport class NanotronUrl extends URL {\n protected static versionPattern_ = new RegExp('^/v[0-9]+/');\n\n readonly method: HttpMethod;\n readonly debugId: string;\n\n constructor(clientRequest: NativeClientRequest, prefix: `/${string}/` | '/') {\n let url = clientRequest.url ?? '';\n if (prefix !== '/' && url.indexOf(prefix) === 0) {\n url = url.slice(prefix.length - 1); // include `/`\n }\n url = url.replace(NanotronUrl.versionPattern_, '/');\n\n super(url, 'http://hostname/');\n\n this.method = (clientRequest.method ?? 'GET').toUpperCase() as HttpMethod;\n\n this.debugId = `[${this.method}]${this.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olib", "import_nanolib"]
7
7
  }
package/dist/main.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /* @alwatr/nanotron-api-server v4.6.0 */
1
+ /* @alwatr/nanotron-api-server v4.8.0 */
2
2
 
3
3
  // src/api-server.ts
4
4
  import { createServer } from "node:http";
@@ -389,8 +389,15 @@ var NanotronServerResponse = class {
389
389
  this.logger_.logMethodArgs?.("new", this.clientRequest.url.debugId);
390
390
  this.headers = {
391
391
  server: "Alwatr Nanotron",
392
- "content-type": "text/plain"
392
+ "content-type": "text/plain charset=UTF-8"
393
393
  };
394
+ const crossOrigin = this.clientRequest.routeOption?.crossOrigin;
395
+ if (crossOrigin?.enable === true) {
396
+ this.headers["access-control-allow-origin"] = crossOrigin.origin;
397
+ this.headers["access-control-allow-methods"] = crossOrigin.methods;
398
+ this.headers["access-control-allow-headers"] = crossOrigin.headers;
399
+ this.headers["access-control-max-age"] = crossOrigin.maxAge;
400
+ }
394
401
  }
395
402
  get hasBeenSent() {
396
403
  return this.hasBeenSent_;
@@ -603,7 +610,7 @@ _NanotronUrl.versionPattern_ = new RegExp("^/v[0-9]+/");
603
610
  var NanotronUrl = _NanotronUrl;
604
611
 
605
612
  // src/api-server.ts
606
- __dev_mode__: packageTracer.add("@alwatr/nanotron-api-server", "4.6.0");
613
+ __dev_mode__: packageTracer.add("@alwatr/nanotron-api-server", "4.8.0");
607
614
  var _NanotronApiServer = class _NanotronApiServer {
608
615
  constructor(config) {
609
616
  this.config_ = {
@@ -635,12 +642,10 @@ var _NanotronApiServer = class _NanotronApiServer {
635
642
  });
636
643
  this.httpServer.on("error", this.handleServerError_);
637
644
  this.httpServer.on("clientError", this.handleClientError_);
645
+ this.defineCorsRoute_();
638
646
  if (this.config_.healthRoute) {
639
647
  this.defineHealthRoute_();
640
648
  }
641
- if (this.config_.allowAllOrigin === true) {
642
- this.defineCorsRoute_();
643
- }
644
649
  }
645
650
  close() {
646
651
  this.logger_.logMethod?.("close");
@@ -679,6 +684,7 @@ var _NanotronApiServer = class _NanotronApiServer {
679
684
  preHandlers: [],
680
685
  postHandlers: [],
681
686
  bodyLimit: this.config_.bodyLimit,
687
+ crossOrigin: this.config_.crossOrigin,
682
688
  ...option
683
689
  };
684
690
  this.logger_.logMethodArgs?.("defineRoute", option_);
@@ -716,9 +722,6 @@ var _NanotronApiServer = class _NanotronApiServer {
716
722
  const url = new NanotronUrl(nativeClientRequest, this.config_.prefix);
717
723
  const routeOption = this.getRouteOption_(url);
718
724
  const connection = new NanotronClientRequest(url, nativeClientRequest, nativeServerResponse, routeOption);
719
- if (this.config_.allowAllOrigin === true) {
720
- connection.serverResponse.headers["access-control-allow-origin"] = "*";
721
- }
722
725
  if (routeOption === null) {
723
726
  connection.serverResponse.statusCode = HttpStatusCodes.Error_Client_404_Not_Found;
724
727
  connection.serverResponse.replyError();
@@ -758,16 +761,21 @@ var _NanotronApiServer = class _NanotronApiServer {
758
761
  }
759
762
  defineCorsRoute_() {
760
763
  this.logger_.logMethod?.("defineCorsRoute_");
764
+ const crossOrigin = this.config_.crossOrigin;
765
+ if (crossOrigin?.enable !== true) return;
761
766
  this.defineRoute({
762
767
  method: "OPTIONS",
763
768
  matchType: "startsWith",
764
769
  url: "/",
765
770
  handler: function() {
766
771
  const res = this.serverResponse.raw_;
767
- res.statusCode = HttpStatusCodes.Success_204_No_Content;
768
- res.setHeader("access-control-allow-origin", "*");
769
- res.setHeader("access-control-allow-methods", "*");
770
- res.setHeader("access-control-allow-headers", "*");
772
+ res.writeHead(HttpStatusCodes.Success_204_No_Content, {
773
+ "access-control-allow-origin": crossOrigin.origin,
774
+ "access-control-allow-methods": crossOrigin.methods,
775
+ "access-control-allow-headers": crossOrigin.headers,
776
+ "access-control-max-age": crossOrigin.maxAge + "",
777
+ "content-length": 0
778
+ });
771
779
  res.end();
772
780
  }
773
781
  });
@@ -780,7 +788,14 @@ _NanotronApiServer.defaultConfig_ = {
780
788
  headersTimeout: 13e4,
781
789
  keepAliveTimeout: 12e4,
782
790
  healthRoute: true,
783
- allowAllOrigin: false,
791
+ crossOrigin: {
792
+ enable: false,
793
+ origin: "*",
794
+ methods: "*",
795
+ headers: "*",
796
+ maxAge: 86400
797
+ // 24h
798
+ },
784
799
  prefix: "/api/",
785
800
  bodyLimit: 1048576
786
801
  // 1MiB
package/dist/main.mjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/api-server.ts", "../src/api-client-request.ts", "../src/api-server-response.ts", "../src/const.ts", "../src/url.ts"],
4
- "sourcesContent": ["import {createServer} from 'node:http';\n\nimport {createLogger, packageTracer} from '@alwatr/nanolib';\n\nimport {NanotronClientRequest} from './api-client-request.js';\nimport {HttpStatusCodes, HttpStatusMessages} from './const.js';\nimport {NanotronUrl} from './url.js';\n\nimport type {DefineRouteOption, MatchType, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {Duplex} from 'node:stream';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Configuration options for the NanotronApiServer.\n */\nexport interface NanotronApiServerConfig {\n /**\n * The port number to listen on.\n *\n * @default 80\n */\n port?: number;\n\n /**\n * The hostname to listen on.\n *\n * @default '0.0.0.0'\n */\n host?: string;\n\n /**\n * Sets the timeout (ms) for receiving the entire request from the client.\n *\n * @default 10_000 ms\n */\n requestTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * This should be bigger than `keepAliveTimeout + your server's expected response time`.\n *\n * @default 130_000 ms\n */\n headersTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * @default 120_000 ms\n */\n keepAliveTimeout?: number;\n\n /**\n * Add /health route.\n *\n * @default true\n */\n healthRoute?: boolean;\n\n /**\n * Add OPTIONS route for preflight requests to allow access all origins.\n *\n * @default false\n */\n allowAllOrigin?: boolean;\n\n /**\n * A prefix to be added to the beginning of the `url` of all defined routes.\n *\n * @default '/api/'\n */\n prefix?: `/${string}/` | '/';\n\n /**\n * The maximum size of the request body in bytes.\n *\n * @default `1_048_576` (1MiB)\n */\n bodyLimit?: number;\n}\n\nexport class NanotronApiServer {\n protected static readonly defaultConfig_: Readonly<Required<NanotronApiServerConfig>> = {\n host: '0.0.0.0',\n port: 80,\n requestTimeout: 10_000,\n headersTimeout: 130_000,\n keepAliveTimeout: 120_000,\n healthRoute: true,\n allowAllOrigin: false,\n prefix: '/api/',\n bodyLimit: 1_048_576, // 1MiB\n };\n\n readonly config_;\n protected readonly logger_;\n\n readonly httpServer;\n\n protected readonly routeHandlerList__: Record<MatchType, DictionaryOpt<DictionaryOpt<Required<DefineRouteOption>>>>;\n\n constructor(config?: Partial<NanotronApiServerConfig>) {\n // Merge the config with the default config.\n this.config_ = {\n ...NanotronApiServer.defaultConfig_,\n ...config,\n };\n\n // Create logger.\n this.logger_ = createLogger('nt-api-server' + (this.config_.port !== 80 ? ':' + this.config_.port : ''));\n this.logger_.logMethodArgs?.('new', {config: this.config_});\n\n // Bind methods.\n this.handleClientRequest_ = this.handleClientRequest_.bind(this);\n this.handleServerError_ = this.handleServerError_.bind(this);\n this.handleClientError_ = this.handleClientError_.bind(this);\n\n // Initialize route handler list.\n this.routeHandlerList__ = {\n exact: {},\n startsWith: {},\n };\n\n // Create the HTTP server.\n this.httpServer = createServer(\n {\n keepAlive: true,\n keepAliveInitialDelay: 0,\n noDelay: true,\n },\n this.handleClientRequest_,\n );\n\n // Configure the server.\n this.httpServer.requestTimeout = this.config_.requestTimeout;\n this.httpServer.keepAliveTimeout = this.config_.keepAliveTimeout;\n this.httpServer.headersTimeout = this.config_.headersTimeout;\n\n // Start the server.\n this.httpServer.listen(this.config_.port, this.config_.host, () => {\n this.logger_.logOther?.(`listening on ${this.config_.host}:${this.config_.port}`);\n });\n\n // Handle server errors.\n this.httpServer.on('error', this.handleServerError_);\n this.httpServer.on('clientError', this.handleClientError_);\n\n if (this.config_.healthRoute) {\n this.defineHealthRoute_();\n }\n\n if (this.config_.allowAllOrigin === true) {\n this.defineCorsRoute_();\n }\n }\n\n close(): void {\n this.logger_.logMethod?.('close');\n this.httpServer.close();\n }\n\n protected getRouteOption_(url: NanotronUrl): Required<DefineRouteOption> | null {\n this.logger_.logMethod?.('getRouteOption_');\n\n if (\n Object.hasOwn(this.routeHandlerList__.exact, url.method) &&\n Object.hasOwn(this.routeHandlerList__.exact[url.method]!, url.pathname)\n ) {\n return this.routeHandlerList__.exact[url.method]![url.pathname]!;\n }\n\n if (Object.hasOwn(this.routeHandlerList__.startsWith, url.method)) {\n const routeList = this.routeHandlerList__.startsWith[url.method];\n for (const pathname in routeList) {\n if (pathname.indexOf(url.pathname) === 0) {\n return routeList[pathname]!;\n }\n }\n }\n\n this.logger_.incident?.('getRouteOption_', 'route_not_found', {method: url.method, url: url.pathname});\n return null;\n }\n\n protected setRouteOption_(option: Required<DefineRouteOption>): void {\n this.logger_.logMethodArgs?.('setRouteOption_', option);\n\n const routeHandlerList = this.routeHandlerList__[option.matchType];\n\n routeHandlerList[option.method] ??= {};\n\n if (Object.hasOwn(routeHandlerList[option.method]!, option.url)) {\n this.logger_.error('defineRoute', 'route_already_exists', option);\n throw new Error('route_already_exists');\n }\n\n routeHandlerList[option.method]![option.url] = option;\n }\n\n defineRoute<TSharedMeta extends DictionaryOpt = DictionaryOpt>(option: DefineRouteOption<TSharedMeta>): void {\n const option_: Required<DefineRouteOption<TSharedMeta>> = {\n matchType: 'exact',\n preHandlers: [],\n postHandlers: [],\n bodyLimit: this.config_.bodyLimit,\n ...option,\n };\n this.logger_.logMethodArgs?.('defineRoute', option_);\n this.setRouteOption_(option_ as Required<DefineRouteOption>);\n }\n\n protected handleServerError_(error: NodeJS.ErrnoException): void {\n if (error.code === 'EADDRINUSE') {\n this.logger_.error('handleServerError_', 'address_in_use', error);\n }\n else {\n this.logger_.error('handleServerError_', 'http_server_error', error);\n }\n }\n\n protected handleClientError_(err: NodeJS.ErrnoException, socket: Duplex): void {\n this.logger_.accident('handleClientError_', 'http_server_client_error', {\n errCode: err.code,\n errMessage: err.message,\n });\n\n const errorCode = err.code?.toLowerCase() ?? `error_${HttpStatusCodes.Error_Client_400_Bad_Request}`;\n const errorMessage = err.message ?? HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request];\n const errorResponse = `{\"ok\":false,\"errorCode\":\"${errorCode}\",\"errorMessage\":\"${errorMessage}\"}`;\n\n const responseHeaders = [\n `HTTP/1.1 ${HttpStatusCodes.Error_Client_400_Bad_Request} ${HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request]}`,\n 'content-type: application/json',\n `content-length: ${Buffer.byteLength(errorResponse)}`,\n '\\r\\n',\n ].join('\\r\\n');\n\n socket.end(responseHeaders + errorResponse);\n }\n\n protected async handleClientRequest_(\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n ): Promise<void> {\n this.logger_.logMethod?.('handleClientRequest_');\n\n if (nativeClientRequest.url === undefined) {\n this.logger_.accident('handleClientRequest_', 'http_server_url_undefined');\n return;\n }\n\n const url = new NanotronUrl(nativeClientRequest, this.config_.prefix);\n\n const routeOption = this.getRouteOption_(url);\n\n const connection = new NanotronClientRequest(url, nativeClientRequest, nativeServerResponse, routeOption);\n\n if (this.config_.allowAllOrigin === true) {\n connection.serverResponse.headers['access-control-allow-origin'] = '*';\n }\n\n if (routeOption === null) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Client_404_Not_Found;\n connection.serverResponse.replyError();\n return;\n }\n\n try {\n for (const handler of routeOption.preHandlers) {\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n if (connection.terminatedHandlers === true) return; // must check after each pre-handler.\n }\n\n await routeOption.handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n\n for (const handler of routeOption.postHandlers) {\n if (connection.terminatedHandlers === true) return; // must check before each post-handler.\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n }\n }\n catch (error) {\n this.logger_.error('handleClientRequest_', 'route_handler_error', error, url.debugId);\n\n if (connection.serverResponse.statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n }\n connection.serverResponse.replyError(error);\n }\n\n // TODO: handled open remained connections.\n }\n\n protected defineHealthRoute_(): void {\n this.logger_.logMethod?.('defineHealthRoute_');\n\n this.defineRoute({\n method: 'GET',\n url: '/health',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.statusCode = HttpStatusCodes.Success_200_OK;\n res.setHeader('server', 'Alwatr Nanotron');\n res.setHeader('content-type', 'application/json');\n res.end('{\"ok\":true}');\n },\n });\n }\n\n protected defineCorsRoute_(): void {\n this.logger_.logMethod?.('defineCorsRoute_');\n\n this.defineRoute({\n method: 'OPTIONS',\n matchType: 'startsWith',\n url: '/',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.statusCode = HttpStatusCodes.Success_204_No_Content;\n res.setHeader('access-control-allow-origin', '*');\n res.setHeader('access-control-allow-methods', '*');\n res.setHeader('access-control-allow-headers', '*');\n res.end();\n },\n });\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {NanotronServerResponse} from './api-server-response.js';\nimport {HttpStatusCodes} from './const.js';\n\nimport type {DefineRouteOption, HttpRequestHeaders, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {NanotronUrl} from './url.js';\n\nexport class NanotronClientRequest<TSharedMeta extends DictionaryOpt = DictionaryOpt> {\n readonly url: NanotronUrl;\n\n readonly serverResponse: NanotronServerResponse;\n\n readonly routeOption: Required<DefineRouteOption> | null;\n\n /**\n * A flag to indicate if the running handlers queue has been terminated.\n * This can occur due to an error being thrown or by explicitly calling the `replyError` method.\n *\n * When `terminatedHandlers` is set to `true`, it signifies that the execution of the current\n * sequence of handlers (including pre, main, and post handlers) has been halted and no further\n * handlers in the queue will be executed.\n *\n * Usage:\n * - Check this flag to determine if the handlers queue has been interrupted.\n * - Set this flag to `true` to manually stop the execution of subsequent handlers.\n */\n terminatedHandlers?: true;\n\n readonly sharedMeta: TSharedMeta = {} as TSharedMeta;\n\n readonly raw_: NativeClientRequest;\n\n protected readonly logger_;\n\n readonly remoteAddress: string | null;\n\n get headers(): HttpRequestHeaders {\n return this.raw_.headers;\n }\n\n private queryParams__?: DictionaryOpt<string>;\n get queryParams(): DictionaryOpt<string> {\n if (this.queryParams__ === undefined) {\n this.queryParams__ = {};\n for (const [key, value] of this.url.searchParams.entries()) {\n this.queryParams__[key] = value;\n }\n }\n return this.queryParams__;\n }\n\n constructor(\n url: NanotronUrl,\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n routeOption: Required<DefineRouteOption> | null,\n ) {\n // Store public properties.\n this.raw_ = nativeClientRequest;\n this.url = url;\n this.routeOption = routeOption;\n\n // Get and store remote address.\n this.remoteAddress = this.getRemoteAddress__();\n\n // Create logger.\n this.logger_ = createLogger(`nt-client-request(${this.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', url.debugId);\n\n // Create server response.\n this.serverResponse = new NanotronServerResponse(this, nativeServerResponse);\n }\n\n getBodyRaw(): Promise<Buffer> {\n return new Promise((resolve, reject) => {\n // method must be POST or PUT or PATCH\n const method = this.url.method;\n if (!(method === 'POST' || method === 'PUT' || method === 'PATCH')) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_405_Method_Not_Allowed;\n return reject(new Error('body_not_allowed'));\n }\n\n const contentLength = +this.raw_.headers['content-length']!;\n\n if (Number.isNaN(contentLength) || contentLength === 0) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_411_Length_Required;\n return reject(new Error('body_length_required'));\n }\n\n if (contentLength > this.routeOption!.bodyLimit) {\n // TODO: routeOption when null?!\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const dataChunks: Uint8Array[] = [];\n let receivedLength = 0;\n\n const onData = (chunk: Uint8Array) => {\n receivedLength += chunk.length;\n dataChunks.push(chunk);\n\n if (receivedLength > this.routeOption!.bodyLimit) {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n dataChunks.length = 0; // free memory\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n };\n\n const onEnd = (err?: Error) => {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n\n if (err !== undefined) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_400_Bad_Request;\n return reject(err);\n }\n\n if (receivedLength !== contentLength) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const body = Buffer.concat(dataChunks);\n\n resolve(body);\n };\n\n this.raw_.on('data', onData);\n this.raw_.on('end', onEnd);\n this.raw_.on('error', onEnd);\n this.raw_.resume();\n });\n }\n\n private getRemoteAddress__(): string | null {\n return this.raw_.headers['x-forwarded-for']?.split(',').pop()?.trim() || this.raw_.socket.remoteAddress || null;\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {type HttpStatusCode, HttpStatusCodes, HttpStatusMessages} from './const.js';\n\nimport type {NanotronClientRequest} from './api-client-request.js';\nimport type {HttpResponseHeaders, ErrorResponse, NativeServerResponse} from './type.js';\n\n/**\n * Configuration options for the Nanotron Api Server Response.\n */\nexport interface NanotronServerResponseConfig {\n clientRequest: NanotronClientRequest;\n}\n\nexport class NanotronServerResponse {\n readonly clientRequest: NanotronClientRequest;\n\n readonly raw_: NativeServerResponse;\n\n readonly headers: HttpResponseHeaders;\n\n protected readonly logger_;\n\n protected hasBeenSent_ = false;\n get hasBeenSent(): boolean {\n return this.hasBeenSent_;\n }\n\n constructor(nanotronClientRequest: NanotronClientRequest, nativeServerResponse: NativeServerResponse) {\n // Store public properties.\n this.clientRequest = nanotronClientRequest;\n this.raw_ = nativeServerResponse;\n\n // Create logger.\n this.logger_ = createLogger(`nt-server-response(${this.clientRequest.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', this.clientRequest.url.debugId);\n\n // Set default reply headers.\n this.headers = {\n server: 'Alwatr Nanotron',\n 'content-type': 'text/plain',\n };\n }\n\n get statusCode(): HttpStatusCode {\n return this.raw_.statusCode as HttpStatusCode;\n }\n\n set statusCode(value: HttpStatusCode) {\n this.raw_.statusCode = value;\n }\n\n protected applyHeaders_() {\n this.logger_.logMethodArgs?.('applyHeaders_', this.headers);\n for (const key in this.headers) {\n this.raw_.setHeader(key, this.headers[key as Lowercase<string>]!);\n }\n }\n\n replyErrorResponse(errorResponse: ErrorResponse): void {\n this.logger_.logMethod?.('replyErrorResponse');\n this.clientRequest.terminatedHandlers = true;\n this.headers['content-type'] = 'application/json';\n let meta = '';\n if (errorResponse.meta !== undefined) {\n const metaType = typeof errorResponse.meta;\n if (\n metaType === 'string' ||\n metaType === 'number' ||\n metaType === 'boolean' ||\n errorResponse.meta === null) {\n meta = `,\"meta\":\"${errorResponse.meta}\"`;\n }\n else if (metaType === 'object') {\n meta = `,\"meta\":${JSON.stringify(errorResponse.meta)}`;\n }\n }\n const responseString = `{\"ok\":false,\"errorCode\":\"${errorResponse.errorCode}\",\"errorMessage\":\"${errorResponse.errorMessage}\"${meta}}`;\n this.reply(responseString);\n }\n\n replyError(error?: Error | string | Json | unknown): void {\n this.logger_.logMethodArgs?.('replyError', {error});\n\n this.clientRequest.terminatedHandlers = true;\n let statusCode = this.statusCode;\n\n if (statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n this.statusCode = statusCode = 500;\n }\n\n if (error instanceof Error) {\n this.replyErrorResponse({\n ok: false,\n errorCode: (error.name === 'Error' ? 'error_' + statusCode : (error.name + '').toLowerCase()) as Lowercase<string>,\n errorMessage: error.message,\n });\n }\n else if (typeof error === 'string') {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: error,\n });\n }\n else if (typeof error === 'object' && error !== null) {\n this.replyJson(error as Json);\n }\n else {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: HttpStatusMessages[statusCode],\n });\n }\n }\n\n replyJson(responseJson: Json): void {\n this.logger_.logMethodArgs?.('replyJson', {responseJson});\n\n let responseString: string;\n try {\n responseString = JSON.stringify(responseJson);\n }\n catch (error) {\n this.logger_.error('replyJson', 'reply_json_stringify_failed', error, this.clientRequest.url.debugId);\n this.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n this.replyErrorResponse({\n ok: false,\n errorCode: 'reply_json_stringify_failed',\n errorMessage: 'Failed to stringify response JSON.',\n });\n return;\n }\n\n this.headers['content-type'] = 'application/json';\n this.reply(responseString);\n }\n\n reply(context: string | Buffer): void {\n this.logger_.logMethodArgs?.('reply', this.clientRequest.url.debugId);\n\n if (this.raw_.writableFinished && this.hasBeenSent_ === false) {\n // The response has already been sent by direct access to the server api.\n this.logger_.accident('reply', 'server_response_writable_finished_directly');\n this.hasBeenSent_ = true;\n }\n\n if (this.hasBeenSent_) {\n this.logger_.accident('reply', 'reply_already_sent', {\n url: this.clientRequest.url.debugId,\n replySent: this.hasBeenSent_,\n writableFinished: this.raw_.writableFinished,\n });\n return;\n }\n\n this.hasBeenSent_ = true;\n\n try {\n if (typeof context === 'string') {\n context = Buffer.from(context);\n }\n\n this.headers['content-length'] = context.byteLength;\n\n this.applyHeaders_();\n this.raw_.end(context, 'binary');\n }\n catch (error) {\n this.logger_.error('reply', 'server_response_error', error, this.clientRequest.url.debugId);\n this.hasBeenSent_ = false;\n }\n }\n}\n", "/**\n * Object representing standard HTTP methods.\n */\nexport const HttpMethods = {\n /**\n * GET: Requests a representation of the specified resource.\n */\n GET: 'GET',\n\n /**\n * HEAD: Asks for a response identical to that of a GET request, but without the response body.\n */\n HEAD: 'HEAD',\n\n /**\n * POST: Submits data to be processed (e.g., from an HTML form) to the identified resource.\n */\n POST: 'POST',\n\n /**\n * PUT: Uploads a representation of the specified URI.\n */\n PUT: 'PUT',\n\n /**\n * DELETE: Deletes the specified resource.\n */\n DELETE: 'DELETE',\n\n /**\n * CONNECT: Establishes a tunnel to the server identified by the target resource.\n */\n CONNECT: 'CONNECT',\n\n /**\n * OPTIONS: Describes the communication options for the target resource.\n */\n OPTIONS: 'OPTIONS',\n\n /**\n * TRACE: Performs a message loop-back test along the path to the target resource.\n */\n TRACE: 'TRACE',\n\n /**\n * PATCH: Applies partial modifications to a resource.\n */\n PATCH: 'PATCH'\n} as const;\n\n/**\n * Object representing standard HTTP status codes.\n */\nexport const HttpStatusCodes = {\n /**\n * 100 Continue: The server has received the request headers and the client should proceed to send the request body.\n */\n Info_100_Continue: 100,\n\n /**\n * 101 Switching Protocols: The server understands and is willing to comply with the clients request to switch protocols.\n */\n Info_101_Switching_Protocols: 101,\n\n /**\n * 102 Processing: The server has received and is processing the request, but no response is available yet.\n */\n Info_102_Processing: 102,\n\n /**\n * 103 Early Hints: The server is sending some response headers before the final HTTP message.\n */\n Info_103_Early_Hints: 103,\n\n /**\n * 200 OK: The request has succeeded.\n */\n Success_200_OK: 200,\n\n /**\n * 201 Created: The request has been fulfilled and resulted in a new resource being created.\n */\n Success_201_Created: 201,\n\n /**\n * 202 Accepted: The request has been accepted for processing, but the processing has not been completed.\n */\n Success_202_Accepted: 202,\n\n /**\n * 203 Non-Authoritative Information: The server is a transforming proxy that received a 200 OK\n * from the origin server but is returning a modified version of the origins response.\n */\n Success_203_Non_Authoritative_Information: 203,\n\n /**\n * 204 No Content: The server successfully processed the request and is not returning any content.\n */\n Success_204_No_Content: 204,\n\n /**\n * 205 Reset Content: The server successfully processed the request,\n * asks that the client reset its document view, and is not returning any content.\n */\n Success_205_Reset_Content: 205,\n\n /**\n * 206 Partial Content: The server is delivering only part of the resource due to a range header sent by the client.\n */\n Success_206_Partial_Content: 206,\n\n /**\n * 207 Multi-Status: The message body that follows is an XML message\n * and can contain a number of separate response codes, depending on how many sub-requests were made.\n */\n Success_207_Multi_Status: 207,\n\n /**\n * 208 Already Reported: The members of a DAV binding have already been enumerated\n * in a preceding part of the (multi-status) response, and are not being included again.\n */\n Success_208_Already_Reported: 208,\n\n /**\n * 226 IM Used: The server has fulfilled a request for the resource, and the response is a representation\n * of the result of one or more instance-manipulations applied to the current instance.\n */\n Success_226_IM_Used: 226,\n\n /**\n * 300 Multiple Choices: The request has more than one possible response.\n */\n Redirect_300_Multiple_Choices: 300,\n\n /**\n * 301 Moved Permanently: The URL of the requested resource has been changed permanently.\n */\n Redirect_301_Moved_Permanently: 301,\n\n /**\n * 302 Found: The URL of the requested resource has been changed temporarily.\n */\n Redirect_302_Found: 302,\n\n /**\n * 303 See Other: The response to the request can be found under another URI using a GET method.\n */\n Redirect_303_See_Other: 303,\n\n /**\n * 304 Not Modified: The resource has not been modified since the version specified\n * by the request headers If-Modified-Since or If-None-Match.\n */\n Redirect_304_Not_Modified: 304,\n\n /**\n * 305 Use Proxy: The requested resource is only available through a proxy, the address for which is provided in the response.\n */\n Redirect_305_Use_Proxy: 305,\n\n /**\n * 306 Switch Proxy: No longer used. Originally meant \"Subsequent requests should use the specified proxy.\"\n */\n Redirect_306_Switch_Proxy: 306,\n\n /**\n * 307 Temporary Redirect: The server sends this response to direct the client\n * to get the requested resource at another URI with the same method that was used in the prior request.\n */\n Redirect_307_Temporary_Redirect: 307,\n\n /**\n * 308 Permanent Redirect: This means that the resource is now permanently located at another URI,\n * specified by the Location: HTTP Response header.\n */\n Redirect_308_Permanent_Redirect: 308,\n\n /**\n * 400 Bad Request: The server cannot or will not process the request due to something that is perceived to be a client error.\n */\n Error_Client_400_Bad_Request: 400,\n\n /**\n * 401 Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource.\n */\n Error_Client_401_Unauthorized: 401,\n\n /**\n * 402 Payment Required: Reserved for future use.\n */\n Error_Client_402_Payment_Required: 402,\n\n /**\n * 403 Forbidden: The client does not have access rights to the content, so the server is refusing to give the requested resource.\n */\n Error_Client_403_Forbidden: 403,\n\n /**\n * 404 Not Found: The server can not find the requested resource.\n */\n Error_Client_404_Not_Found: 404,\n\n /**\n * 405 Method Not Allowed: The request method is known by the server but is not supported by the target resource.\n */\n Error_Client_405_Method_Not_Allowed: 405,\n\n /**\n * 406 Not Acceptable: The target resource does not have a current representation that would be acceptable\n * to the user agent, according to the proactive negotiation header fields received in the request,\n * and the server is unwilling to supply a default representation.\n */\n Error_Client_406_Not_Acceptable: 406,\n\n /**\n * 407 Proxy Authentication Required: Similar to 401 Unauthorized,\n * but it indicates that the client needs to authenticate itself in order to use a proxy.\n */\n Error_Client_407_Proxy_Authentication_Required: 407,\n\n /**\n * 408 Request Timeout: The server timed out waiting for the request.\n */\n Error_Client_408_Request_Timeout: 408,\n\n /**\n * 409 Conflict: The request could not be processed because of conflict in the request, such as an edit conflict.\n */\n Error_Client_409_Conflict: 409,\n\n /**\n * 410 Gone: The requested resource is no longer available and will not be available again.\n */\n Error_Client_410_Gone: 410,\n\n /**\n * 411 Length Required: The server refuses to accept the request without a defined Content-Length header.\n */\n Error_Client_411_Length_Required: 411,\n\n /**\n * 412 Precondition Failed: One or more conditions given in the request header fields evaluated to false when tested on the server.\n */\n Error_Client_412_Precondition_Failed: 412,\n\n /**\n * 413 Payload Too Large: The server is refusing to process a request because the request payload is larger\n * than the server is willing or able to process.\n */\n Error_Client_413_Payload_Too_Large: 413,\n\n /**\n * 414 URI Too Long: The server is refusing to service the request because the URI is longer than the server is willing to interpret.\n */\n Error_Client_414_URI_Too_Long: 414,\n\n /**\n * 415 Unsupported Media Type: The server is refusing to service the request\n * because the entity of the request is in a format not supported by the requested resource for the requested method.\n */\n Error_Client_415_Unsupported_Media_Type: 415,\n\n /**\n * 416 Range Not Satisfiable: The client has asked for a portion of the file, but the server cannot supply that portion.\n */\n Error_Client_416_Range_Not_Satisfiable: 416,\n\n /**\n * 417 Expectation Failed: The server cannot meet the requirements of the Expect request-header field.\n */\n Error_Client_417_Expectation_Failed: 417,\n\n /**\n * 421 Misdirected Request: The request was directed at a server that is not able to produce a response.\n */\n Error_Client_421_Misdirected_Request: 421,\n\n /**\n * 422 Unprocessable Entity: The request was well-formed but was unable to be followed due to semantic errors.\n */\n Error_Client_422_Unprocessable_Entity: 422,\n\n /**\n * 423 Locked: The resource that is being accessed is locked.\n */\n Error_Client_423_Locked: 423,\n\n /**\n * 424 Failed Dependency: The request failed due to a failure of a previous request.\n */\n Error_Client_424_Failed_Dependency: 424,\n\n /**\n * 425 Too Early: The server is unwilling to risk processing a request that might be replayed.\n */\n Error_Client_425_Too_Early: 425,\n\n /**\n * 426 Upgrade Required: The server refuses to perform the request using the current protocol\n * but might be willing to do so after the client upgrades to a different protocol.\n */\n Error_Client_426_Upgrade_Required: 426,\n\n /**\n * 428 Precondition Required: The origin server requires the request to be conditional.\n */\n Error_Client_428_Precondition_Required: 428,\n\n /**\n * 429 Too Many Requests: The user has sent too many requests in a given amount of time (\"rate limiting\").\n */\n Error_Client_429_Too_Many_Requests: 429,\n\n /**\n * 431 Request Header Fields Too Large: The server is unwilling to process the request because its header fields are too large.\n */\n Error_Client_431_Request_Header_Fields_Too_Large: 431,\n\n /**\n * 451 Unavailable For Legal Reasons: The user requests an illegal resource, such as a web page censored by a government.\n */\n Error_Client_451_Unavailable_For_Legal_Reasons: 451,\n\n /**\n * 500 Internal Server Error: A generic error message, given when no more specific message is suitable.\n */\n Error_Server_500_Internal_Server_Error: 500,\n\n /**\n * 501 Not Implemented: The server either does not recognize the request method, or it lacks the ability to fulfill the request.\n */\n Error_Server_501_Not_Implemented: 501,\n\n /**\n * 502 Bad Gateway: The server was acting as a gateway or proxy and received an invalid response from the upstream server.\n */\n Error_Server_502_Bad_Gateway: 502,\n\n /**\n * 503 Service Unavailable: The server is currently unavailable (because it is overloaded or down for maintenance).\n */\n Error_Server_503_Service_Unavailable: 503,\n\n /**\n * 504 Gateway Timeout: The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.\n */\n Error_Server_504_Gateway_Timeout: 504,\n\n /**\n * 505 HTTP Version Not Supported: The server does not support the HTTP protocol version used in the request.\n */\n Error_Server_505_HTTP_Version_Not_Supported: 505,\n\n /**\n * 506 Variant Also Negotiates: Transparent content negotiation for the request results in a circular reference.\n */\n Error_Server_506_Variant_Also_Negotiates: 506,\n\n /**\n * 507 Insufficient Storage: The server is unable to store the representation needed to complete the request.\n */\n Error_Server_507_Insufficient_Storage: 507,\n\n /**\n * 508 Loop Detected: The server detected an infinite loop while processing the request.\n */\n Error_Server_508_Loop_Detected: 508,\n\n /**\n * 510 Not Extended: Further extensions to the request are required for the server to fulfill it.\n */\n Error_Server_510_Not_Extended: 510,\n\n /**\n * 511 Network Authentication Required: The client needs to authenticate to gain network access.\n */\n Error_Server_511_Network_Authentication_Required: 511\n} as const;\n\nexport const HttpStatusMessages = {\n 100: 'Continue',\n 101: 'Switching Protocols',\n 102: 'Processing',\n 103: 'Early Hints',\n 200: 'OK',\n 201: 'Created',\n 202: 'Accepted',\n 203: 'Non-Authoritative Information',\n 204: 'No Content',\n 205: 'Reset Content',\n 206: 'Partial Content',\n 207: 'Multi-Status',\n 208: 'Already Reported',\n 226: 'IM Used',\n 300: 'Multiple Choices',\n 301: 'Moved Permanently',\n 302: 'Found',\n 303: 'See Other',\n 304: 'Not Modified',\n 305: 'Use Proxy',\n 307: 'Temporary Redirect',\n 308: 'Permanent Redirect',\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Failed',\n 413: 'Payload Too Large',\n 414: 'URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: 'I\\'m a Teapot',\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 425: 'Too Early',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 451: 'Unavailable For Legal Reasons',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 506: 'Variant Also Negotiates',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 509: 'Bandwidth Limit Exceeded',\n 510: 'Not Extended',\n 511: 'Network Authentication Required',\n};\n\nexport type HttpStatusCode = keyof typeof HttpStatusMessages;\n", "import {URL} from 'node:url';\n\nimport type {HttpMethod, NativeClientRequest} from './type.js';\n\nexport class NanotronUrl extends URL {\n protected static versionPattern_ = new RegExp('^/v[0-9]+/');\n\n readonly method: HttpMethod;\n readonly debugId: string;\n\n constructor(clientRequest: NativeClientRequest, prefix: `/${string}/` | '/') {\n let url = clientRequest.url ?? '';\n if (prefix !== '/' && url.indexOf(prefix) === 0) {\n url = url.slice(prefix.length - 1); // include `/`\n }\n url = url.replace(NanotronUrl.versionPattern_, '/');\n\n super(url, 'http://hostname/');\n\n this.method = (clientRequest.method ?? 'GET').toUpperCase() as HttpMethod;\n\n this.debugId = `[${this.method}]${this.pathname}`;\n }\n}\n"],
5
- "mappings": ";;;AAAA,SAAQ,oBAAmB;AAE3B,SAAQ,gBAAAA,eAAc,qBAAoB;;;ACF1C,SAAQ,gBAAAC,qBAAmB;;;ACA3B,SAAQ,oBAAmB;;;ACGpB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA,EAIzB,KAAK;AAAA;AAAA;AAAA;AAAA,EAKL,MAAM;AAAA;AAAA;AAAA;AAAA,EAKN,MAAM;AAA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B;AAE3C,SAAK,YAAY;AAAA,MACf,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,KAAK;AAAA,MACL,SAAS,WAAY;AACnB,cAAM,MAAM,KAAK,eAAe;AAChC,YAAI,aAAa,gBAAgB;AACjC,YAAI,UAAU,+BAA+B,GAAG;AAChD,YAAI,UAAU,gCAAgC,GAAG;AACjD,YAAI,UAAU,gCAAgC,GAAG;AACjD,YAAI,IAAI;AAAA,MACV;AAAA,IACF,CAAC;AAAA,EACH;AACF;AApPa,mBACe,iBAA8D;AAAA,EACtF,MAAM;AAAA,EACN,MAAM;AAAA,EACN,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,QAAQ;AAAA,EACR,WAAW;AAAA;AACb;AAXK,IAAM,oBAAN;",
4
+ "sourcesContent": ["import {createServer} from 'node:http';\n\nimport {createLogger, packageTracer} from '@alwatr/nanolib';\n\nimport {NanotronClientRequest} from './api-client-request.js';\nimport {HttpStatusCodes, HttpStatusMessages} from './const.js';\nimport {NanotronUrl} from './url.js';\n\nimport type {DefineRouteOption, MatchType, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {Duplex} from 'node:stream';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Configuration options for the NanotronApiServer.\n */\nexport interface NanotronApiServerConfig {\n /**\n * The port number to listen on.\n *\n * @default 80\n */\n port?: number;\n\n /**\n * The hostname to listen on.\n *\n * @default '0.0.0.0'\n */\n host?: string;\n\n /**\n * Sets the timeout (ms) for receiving the entire request from the client.\n *\n * @default 10_000 ms\n */\n requestTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * This should be bigger than `keepAliveTimeout + your server's expected response time`.\n *\n * @default 130_000 ms\n */\n headersTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * @default 120_000 ms\n */\n keepAliveTimeout?: number;\n\n /**\n * Add /health route.\n *\n * @default true\n */\n healthRoute?: boolean;\n\n /**\n * Add OPTIONS route for preflight requests to allow access origins.\n *\n * @default {enable: false, origin: '*', methods: '*', headers: '*', maxAge: 86_400}\n */\n crossOrigin?: {\n enable: boolean;\n origin: string;\n methods: string;\n headers: string;\n maxAge: string | number;\n },\n\n /**\n * A prefix to be added to the beginning of the `url` of all defined routes.\n *\n * @default '/api/'\n */\n prefix?: `/${string}/` | '/';\n\n /**\n * The maximum size of the request body in bytes.\n *\n * @default `1_048_576` (1MiB)\n */\n bodyLimit?: number;\n}\n\nexport class NanotronApiServer {\n protected static readonly defaultConfig_: Readonly<Required<NanotronApiServerConfig>> = {\n host: '0.0.0.0',\n port: 80,\n requestTimeout: 10_000,\n headersTimeout: 130_000,\n keepAliveTimeout: 120_000,\n healthRoute: true,\n crossOrigin: {\n enable: false,\n origin: '*',\n methods: '*',\n headers: '*',\n maxAge: 86_400, // 24h\n },\n prefix: '/api/',\n bodyLimit: 1_048_576, // 1MiB\n };\n\n readonly config_: Required<NanotronApiServerConfig>;\n protected readonly logger_;\n\n readonly httpServer;\n\n protected readonly routeHandlerList__: Record<MatchType, DictionaryOpt<DictionaryOpt<Required<DefineRouteOption>>>>;\n\n constructor(config?: Partial<NanotronApiServerConfig>) {\n // Merge the config with the default config.\n this.config_ = {\n ...NanotronApiServer.defaultConfig_,\n ...config,\n };\n\n // Create logger.\n this.logger_ = createLogger('nt-api-server' + (this.config_.port !== 80 ? ':' + this.config_.port : ''));\n this.logger_.logMethodArgs?.('new', {config: this.config_});\n\n // Bind methods.\n this.handleClientRequest_ = this.handleClientRequest_.bind(this);\n this.handleServerError_ = this.handleServerError_.bind(this);\n this.handleClientError_ = this.handleClientError_.bind(this);\n\n // Initialize route handler list.\n this.routeHandlerList__ = {\n exact: {},\n startsWith: {},\n };\n\n // Create the HTTP server.\n this.httpServer = createServer(\n {\n keepAlive: true,\n keepAliveInitialDelay: 0,\n noDelay: true,\n },\n this.handleClientRequest_,\n );\n\n // Configure the server.\n this.httpServer.requestTimeout = this.config_.requestTimeout;\n this.httpServer.keepAliveTimeout = this.config_.keepAliveTimeout;\n this.httpServer.headersTimeout = this.config_.headersTimeout;\n\n // Start the server.\n this.httpServer.listen(this.config_.port, this.config_.host, () => {\n this.logger_.logOther?.(`listening on ${this.config_.host}:${this.config_.port}`);\n });\n\n // Handle server errors.\n this.httpServer.on('error', this.handleServerError_);\n this.httpServer.on('clientError', this.handleClientError_);\n\n this.defineCorsRoute_();\n\n if (this.config_.healthRoute) {\n this.defineHealthRoute_();\n }\n }\n\n close(): void {\n this.logger_.logMethod?.('close');\n this.httpServer.close();\n }\n\n protected getRouteOption_(url: NanotronUrl): Required<DefineRouteOption> | null {\n this.logger_.logMethod?.('getRouteOption_');\n\n if (\n Object.hasOwn(this.routeHandlerList__.exact, url.method) &&\n Object.hasOwn(this.routeHandlerList__.exact[url.method]!, url.pathname)\n ) {\n return this.routeHandlerList__.exact[url.method]![url.pathname]!;\n }\n\n if (Object.hasOwn(this.routeHandlerList__.startsWith, url.method)) {\n const routeList = this.routeHandlerList__.startsWith[url.method];\n for (const pathname in routeList) {\n if (pathname.indexOf(url.pathname) === 0) {\n return routeList[pathname]!;\n }\n }\n }\n\n this.logger_.incident?.('getRouteOption_', 'route_not_found', {method: url.method, url: url.pathname});\n return null;\n }\n\n protected setRouteOption_(option: Required<DefineRouteOption>): void {\n this.logger_.logMethodArgs?.('setRouteOption_', option);\n\n const routeHandlerList = this.routeHandlerList__[option.matchType];\n\n routeHandlerList[option.method] ??= {};\n\n if (Object.hasOwn(routeHandlerList[option.method]!, option.url)) {\n this.logger_.error('defineRoute', 'route_already_exists', option);\n throw new Error('route_already_exists');\n }\n\n routeHandlerList[option.method]![option.url] = option;\n }\n\n defineRoute<TSharedMeta extends DictionaryOpt = DictionaryOpt>(option: DefineRouteOption<TSharedMeta>): void {\n const option_: Required<DefineRouteOption<TSharedMeta>> = {\n matchType: 'exact',\n preHandlers: [],\n postHandlers: [],\n bodyLimit: this.config_.bodyLimit,\n crossOrigin: this.config_.crossOrigin,\n ...option,\n };\n this.logger_.logMethodArgs?.('defineRoute', option_);\n this.setRouteOption_(option_ as Required<DefineRouteOption>);\n }\n\n protected handleServerError_(error: NodeJS.ErrnoException): void {\n if (error.code === 'EADDRINUSE') {\n this.logger_.error('handleServerError_', 'address_in_use', error);\n }\n else {\n this.logger_.error('handleServerError_', 'http_server_error', error);\n }\n }\n\n protected handleClientError_(err: NodeJS.ErrnoException, socket: Duplex): void {\n this.logger_.accident('handleClientError_', 'http_server_client_error', {\n errCode: err.code,\n errMessage: err.message,\n });\n\n const errorCode = err.code?.toLowerCase() ?? `error_${HttpStatusCodes.Error_Client_400_Bad_Request}`;\n const errorMessage = err.message ?? HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request];\n const errorResponse = `{\"ok\":false,\"errorCode\":\"${errorCode}\",\"errorMessage\":\"${errorMessage}\"}`;\n\n const responseHeaders = [\n `HTTP/1.1 ${HttpStatusCodes.Error_Client_400_Bad_Request} ${HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request]}`,\n 'content-type: application/json',\n `content-length: ${Buffer.byteLength(errorResponse)}`,\n '\\r\\n',\n ].join('\\r\\n');\n\n socket.end(responseHeaders + errorResponse);\n }\n\n protected async handleClientRequest_(\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n ): Promise<void> {\n this.logger_.logMethod?.('handleClientRequest_');\n\n if (nativeClientRequest.url === undefined) {\n this.logger_.accident('handleClientRequest_', 'http_server_url_undefined');\n return;\n }\n\n const url = new NanotronUrl(nativeClientRequest, this.config_.prefix);\n\n const routeOption = this.getRouteOption_(url);\n\n const connection = new NanotronClientRequest(url, nativeClientRequest, nativeServerResponse, routeOption);\n\n if (routeOption === null) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Client_404_Not_Found;\n connection.serverResponse.replyError();\n return;\n }\n\n try {\n for (const handler of routeOption.preHandlers) {\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n if (connection.terminatedHandlers === true) return; // must check after each pre-handler.\n }\n\n await routeOption.handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n\n for (const handler of routeOption.postHandlers) {\n if (connection.terminatedHandlers === true) return; // must check before each post-handler.\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n }\n }\n catch (error) {\n this.logger_.error('handleClientRequest_', 'route_handler_error', error, url.debugId);\n\n if (connection.serverResponse.statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n }\n connection.serverResponse.replyError(error);\n }\n\n // TODO: handled open remained connections.\n }\n\n protected defineHealthRoute_(): void {\n this.logger_.logMethod?.('defineHealthRoute_');\n\n this.defineRoute({\n method: 'GET',\n url: '/health',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.statusCode = HttpStatusCodes.Success_200_OK;\n res.setHeader('server', 'Alwatr Nanotron');\n res.setHeader('content-type', 'application/json');\n res.end('{\"ok\":true}');\n },\n });\n }\n\n protected defineCorsRoute_(): void {\n this.logger_.logMethod?.('defineCorsRoute_');\n const crossOrigin = this.config_.crossOrigin;\n if (crossOrigin?.enable !== true) return;\n this.defineRoute({\n method: 'OPTIONS',\n matchType: 'startsWith',\n url: '/',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.writeHead(HttpStatusCodes.Success_204_No_Content, {\n 'access-control-allow-origin': crossOrigin.origin,\n 'access-control-allow-methods': crossOrigin.methods,\n 'access-control-allow-headers': crossOrigin.headers,\n 'access-control-max-age': crossOrigin.maxAge + '',\n 'content-length': 0,\n });\n res.end();\n },\n });\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {NanotronServerResponse} from './api-server-response.js';\nimport {HttpStatusCodes} from './const.js';\n\nimport type {DefineRouteOption, HttpRequestHeaders, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {NanotronUrl} from './url.js';\n\nexport class NanotronClientRequest<TSharedMeta extends DictionaryOpt = DictionaryOpt> {\n readonly url: NanotronUrl;\n\n readonly serverResponse: NanotronServerResponse;\n\n readonly routeOption: Required<DefineRouteOption> | null;\n\n /**\n * A flag to indicate if the running handlers queue has been terminated.\n * This can occur due to an error being thrown or by explicitly calling the `replyError` method.\n *\n * When `terminatedHandlers` is set to `true`, it signifies that the execution of the current\n * sequence of handlers (including pre, main, and post handlers) has been halted and no further\n * handlers in the queue will be executed.\n *\n * Usage:\n * - Check this flag to determine if the handlers queue has been interrupted.\n * - Set this flag to `true` to manually stop the execution of subsequent handlers.\n */\n terminatedHandlers?: true;\n\n readonly sharedMeta: TSharedMeta = {} as TSharedMeta;\n\n readonly raw_: NativeClientRequest;\n\n protected readonly logger_;\n\n readonly remoteAddress: string | null;\n\n get headers(): HttpRequestHeaders {\n return this.raw_.headers;\n }\n\n private queryParams__?: DictionaryOpt<string>;\n get queryParams(): DictionaryOpt<string> {\n if (this.queryParams__ === undefined) {\n this.queryParams__ = {};\n for (const [key, value] of this.url.searchParams.entries()) {\n this.queryParams__[key] = value;\n }\n }\n return this.queryParams__;\n }\n\n constructor(\n url: NanotronUrl,\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n routeOption: Required<DefineRouteOption> | null,\n ) {\n // Store public properties.\n this.raw_ = nativeClientRequest;\n this.url = url;\n this.routeOption = routeOption;\n\n // Get and store remote address.\n this.remoteAddress = this.getRemoteAddress__();\n\n // Create logger.\n this.logger_ = createLogger(`nt-client-request(${this.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', url.debugId);\n\n // Create server response.\n this.serverResponse = new NanotronServerResponse(this, nativeServerResponse);\n }\n\n getBodyRaw(): Promise<Buffer> {\n return new Promise((resolve, reject) => {\n // method must be POST or PUT or PATCH\n const method = this.url.method;\n if (!(method === 'POST' || method === 'PUT' || method === 'PATCH')) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_405_Method_Not_Allowed;\n return reject(new Error('body_not_allowed'));\n }\n\n const contentLength = +this.raw_.headers['content-length']!;\n\n if (Number.isNaN(contentLength) || contentLength === 0) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_411_Length_Required;\n return reject(new Error('body_length_required'));\n }\n\n if (contentLength > this.routeOption!.bodyLimit) {\n // TODO: routeOption when null?!\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const dataChunks: Uint8Array[] = [];\n let receivedLength = 0;\n\n const onData = (chunk: Uint8Array) => {\n receivedLength += chunk.length;\n dataChunks.push(chunk);\n\n if (receivedLength > this.routeOption!.bodyLimit) {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n dataChunks.length = 0; // free memory\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n };\n\n const onEnd = (err?: Error) => {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n\n if (err !== undefined) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_400_Bad_Request;\n return reject(err);\n }\n\n if (receivedLength !== contentLength) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const body = Buffer.concat(dataChunks);\n\n resolve(body);\n };\n\n this.raw_.on('data', onData);\n this.raw_.on('end', onEnd);\n this.raw_.on('error', onEnd);\n this.raw_.resume();\n });\n }\n\n private getRemoteAddress__(): string | null {\n return this.raw_.headers['x-forwarded-for']?.split(',').pop()?.trim() || this.raw_.socket.remoteAddress || null;\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {type HttpStatusCode, HttpStatusCodes, HttpStatusMessages} from './const.js';\n\nimport type {NanotronClientRequest} from './api-client-request.js';\nimport type {HttpResponseHeaders, ErrorResponse, NativeServerResponse} from './type.js';\n\n/**\n * Configuration options for the Nanotron Api Server Response.\n */\nexport interface NanotronServerResponseConfig {\n clientRequest: NanotronClientRequest;\n}\n\nexport class NanotronServerResponse {\n readonly clientRequest: NanotronClientRequest;\n\n readonly raw_: NativeServerResponse;\n\n readonly headers: HttpResponseHeaders;\n\n protected readonly logger_;\n\n protected hasBeenSent_ = false;\n get hasBeenSent(): boolean {\n return this.hasBeenSent_;\n }\n\n constructor(nanotronClientRequest: NanotronClientRequest, nativeServerResponse: NativeServerResponse) {\n // Store public properties.\n this.clientRequest = nanotronClientRequest;\n this.raw_ = nativeServerResponse;\n\n // Create logger.\n this.logger_ = createLogger(`nt-server-response(${this.clientRequest.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', this.clientRequest.url.debugId);\n\n // Set default reply headers.\n this.headers = {\n server: 'Alwatr Nanotron',\n 'content-type': 'text/plain charset=UTF-8',\n };\n\n const crossOrigin = this.clientRequest.routeOption?.crossOrigin;\n if (crossOrigin?.enable === true) {\n this.headers['access-control-allow-origin'] = crossOrigin.origin;\n this.headers['access-control-allow-methods'] = crossOrigin.methods;\n this.headers['access-control-allow-headers'] = crossOrigin.headers;\n this.headers['access-control-max-age'] = crossOrigin.maxAge;\n }\n }\n\n get statusCode(): HttpStatusCode {\n return this.raw_.statusCode as HttpStatusCode;\n }\n\n set statusCode(value: HttpStatusCode) {\n this.raw_.statusCode = value;\n }\n\n protected applyHeaders_() {\n this.logger_.logMethodArgs?.('applyHeaders_', this.headers);\n for (const key in this.headers) {\n this.raw_.setHeader(key, this.headers[key as Lowercase<string>]!);\n }\n }\n\n replyErrorResponse(errorResponse: ErrorResponse): void {\n this.logger_.logMethod?.('replyErrorResponse');\n this.clientRequest.terminatedHandlers = true;\n this.headers['content-type'] = 'application/json';\n let meta = '';\n if (errorResponse.meta !== undefined) {\n const metaType = typeof errorResponse.meta;\n if (\n metaType === 'string' ||\n metaType === 'number' ||\n metaType === 'boolean' ||\n errorResponse.meta === null) {\n meta = `,\"meta\":\"${errorResponse.meta}\"`;\n }\n else if (metaType === 'object') {\n meta = `,\"meta\":${JSON.stringify(errorResponse.meta)}`;\n }\n }\n const responseString = `{\"ok\":false,\"errorCode\":\"${errorResponse.errorCode}\",\"errorMessage\":\"${errorResponse.errorMessage}\"${meta}}`;\n this.reply(responseString);\n }\n\n replyError(error?: Error | string | Json | unknown): void {\n this.logger_.logMethodArgs?.('replyError', {error});\n\n this.clientRequest.terminatedHandlers = true;\n let statusCode = this.statusCode;\n\n if (statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n this.statusCode = statusCode = 500;\n }\n\n if (error instanceof Error) {\n this.replyErrorResponse({\n ok: false,\n errorCode: (error.name === 'Error' ? 'error_' + statusCode : (error.name + '').toLowerCase()) as Lowercase<string>,\n errorMessage: error.message,\n });\n }\n else if (typeof error === 'string') {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: error,\n });\n }\n else if (typeof error === 'object' && error !== null) {\n this.replyJson(error as Json);\n }\n else {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: HttpStatusMessages[statusCode],\n });\n }\n }\n\n replyJson(responseJson: Json): void {\n this.logger_.logMethodArgs?.('replyJson', {responseJson});\n\n let responseString: string;\n try {\n responseString = JSON.stringify(responseJson);\n }\n catch (error) {\n this.logger_.error('replyJson', 'reply_json_stringify_failed', error, this.clientRequest.url.debugId);\n this.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n this.replyErrorResponse({\n ok: false,\n errorCode: 'reply_json_stringify_failed',\n errorMessage: 'Failed to stringify response JSON.',\n });\n return;\n }\n\n this.headers['content-type'] = 'application/json';\n this.reply(responseString);\n }\n\n reply(context: string | Buffer): void {\n this.logger_.logMethodArgs?.('reply', this.clientRequest.url.debugId);\n\n if (this.raw_.writableFinished && this.hasBeenSent_ === false) {\n // The response has already been sent by direct access to the server api.\n this.logger_.accident('reply', 'server_response_writable_finished_directly');\n this.hasBeenSent_ = true;\n }\n\n if (this.hasBeenSent_) {\n this.logger_.accident('reply', 'reply_already_sent', {\n url: this.clientRequest.url.debugId,\n replySent: this.hasBeenSent_,\n writableFinished: this.raw_.writableFinished,\n });\n return;\n }\n\n this.hasBeenSent_ = true;\n\n try {\n if (typeof context === 'string') {\n context = Buffer.from(context);\n }\n\n this.headers['content-length'] = context.byteLength;\n\n this.applyHeaders_();\n this.raw_.end(context, 'binary');\n }\n catch (error) {\n this.logger_.error('reply', 'server_response_error', error, this.clientRequest.url.debugId);\n this.hasBeenSent_ = false;\n }\n }\n}\n", "/**\n * Object representing standard HTTP methods.\n */\nexport const HttpMethods = {\n /**\n * GET: Requests a representation of the specified resource.\n */\n GET: 'GET',\n\n /**\n * HEAD: Asks for a response identical to that of a GET request, but without the response body.\n */\n HEAD: 'HEAD',\n\n /**\n * POST: Submits data to be processed (e.g., from an HTML form) to the identified resource.\n */\n POST: 'POST',\n\n /**\n * PUT: Uploads a representation of the specified URI.\n */\n PUT: 'PUT',\n\n /**\n * DELETE: Deletes the specified resource.\n */\n DELETE: 'DELETE',\n\n /**\n * CONNECT: Establishes a tunnel to the server identified by the target resource.\n */\n CONNECT: 'CONNECT',\n\n /**\n * OPTIONS: Describes the communication options for the target resource.\n */\n OPTIONS: 'OPTIONS',\n\n /**\n * TRACE: Performs a message loop-back test along the path to the target resource.\n */\n TRACE: 'TRACE',\n\n /**\n * PATCH: Applies partial modifications to a resource.\n */\n PATCH: 'PATCH'\n} as const;\n\n/**\n * Object representing standard HTTP status codes.\n */\nexport const HttpStatusCodes = {\n /**\n * 100 Continue: The server has received the request headers and the client should proceed to send the request body.\n */\n Info_100_Continue: 100,\n\n /**\n * 101 Switching Protocols: The server understands and is willing to comply with the clients request to switch protocols.\n */\n Info_101_Switching_Protocols: 101,\n\n /**\n * 102 Processing: The server has received and is processing the request, but no response is available yet.\n */\n Info_102_Processing: 102,\n\n /**\n * 103 Early Hints: The server is sending some response headers before the final HTTP message.\n */\n Info_103_Early_Hints: 103,\n\n /**\n * 200 OK: The request has succeeded.\n */\n Success_200_OK: 200,\n\n /**\n * 201 Created: The request has been fulfilled and resulted in a new resource being created.\n */\n Success_201_Created: 201,\n\n /**\n * 202 Accepted: The request has been accepted for processing, but the processing has not been completed.\n */\n Success_202_Accepted: 202,\n\n /**\n * 203 Non-Authoritative Information: The server is a transforming proxy that received a 200 OK\n * from the origin server but is returning a modified version of the origins response.\n */\n Success_203_Non_Authoritative_Information: 203,\n\n /**\n * 204 No Content: The server successfully processed the request and is not returning any content.\n */\n Success_204_No_Content: 204,\n\n /**\n * 205 Reset Content: The server successfully processed the request,\n * asks that the client reset its document view, and is not returning any content.\n */\n Success_205_Reset_Content: 205,\n\n /**\n * 206 Partial Content: The server is delivering only part of the resource due to a range header sent by the client.\n */\n Success_206_Partial_Content: 206,\n\n /**\n * 207 Multi-Status: The message body that follows is an XML message\n * and can contain a number of separate response codes, depending on how many sub-requests were made.\n */\n Success_207_Multi_Status: 207,\n\n /**\n * 208 Already Reported: The members of a DAV binding have already been enumerated\n * in a preceding part of the (multi-status) response, and are not being included again.\n */\n Success_208_Already_Reported: 208,\n\n /**\n * 226 IM Used: The server has fulfilled a request for the resource, and the response is a representation\n * of the result of one or more instance-manipulations applied to the current instance.\n */\n Success_226_IM_Used: 226,\n\n /**\n * 300 Multiple Choices: The request has more than one possible response.\n */\n Redirect_300_Multiple_Choices: 300,\n\n /**\n * 301 Moved Permanently: The URL of the requested resource has been changed permanently.\n */\n Redirect_301_Moved_Permanently: 301,\n\n /**\n * 302 Found: The URL of the requested resource has been changed temporarily.\n */\n Redirect_302_Found: 302,\n\n /**\n * 303 See Other: The response to the request can be found under another URI using a GET method.\n */\n Redirect_303_See_Other: 303,\n\n /**\n * 304 Not Modified: The resource has not been modified since the version specified\n * by the request headers If-Modified-Since or If-None-Match.\n */\n Redirect_304_Not_Modified: 304,\n\n /**\n * 305 Use Proxy: The requested resource is only available through a proxy, the address for which is provided in the response.\n */\n Redirect_305_Use_Proxy: 305,\n\n /**\n * 306 Switch Proxy: No longer used. Originally meant \"Subsequent requests should use the specified proxy.\"\n */\n Redirect_306_Switch_Proxy: 306,\n\n /**\n * 307 Temporary Redirect: The server sends this response to direct the client\n * to get the requested resource at another URI with the same method that was used in the prior request.\n */\n Redirect_307_Temporary_Redirect: 307,\n\n /**\n * 308 Permanent Redirect: This means that the resource is now permanently located at another URI,\n * specified by the Location: HTTP Response header.\n */\n Redirect_308_Permanent_Redirect: 308,\n\n /**\n * 400 Bad Request: The server cannot or will not process the request due to something that is perceived to be a client error.\n */\n Error_Client_400_Bad_Request: 400,\n\n /**\n * 401 Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource.\n */\n Error_Client_401_Unauthorized: 401,\n\n /**\n * 402 Payment Required: Reserved for future use.\n */\n Error_Client_402_Payment_Required: 402,\n\n /**\n * 403 Forbidden: The client does not have access rights to the content, so the server is refusing to give the requested resource.\n */\n Error_Client_403_Forbidden: 403,\n\n /**\n * 404 Not Found: The server can not find the requested resource.\n */\n Error_Client_404_Not_Found: 404,\n\n /**\n * 405 Method Not Allowed: The request method is known by the server but is not supported by the target resource.\n */\n Error_Client_405_Method_Not_Allowed: 405,\n\n /**\n * 406 Not Acceptable: The target resource does not have a current representation that would be acceptable\n * to the user agent, according to the proactive negotiation header fields received in the request,\n * and the server is unwilling to supply a default representation.\n */\n Error_Client_406_Not_Acceptable: 406,\n\n /**\n * 407 Proxy Authentication Required: Similar to 401 Unauthorized,\n * but it indicates that the client needs to authenticate itself in order to use a proxy.\n */\n Error_Client_407_Proxy_Authentication_Required: 407,\n\n /**\n * 408 Request Timeout: The server timed out waiting for the request.\n */\n Error_Client_408_Request_Timeout: 408,\n\n /**\n * 409 Conflict: The request could not be processed because of conflict in the request, such as an edit conflict.\n */\n Error_Client_409_Conflict: 409,\n\n /**\n * 410 Gone: The requested resource is no longer available and will not be available again.\n */\n Error_Client_410_Gone: 410,\n\n /**\n * 411 Length Required: The server refuses to accept the request without a defined Content-Length header.\n */\n Error_Client_411_Length_Required: 411,\n\n /**\n * 412 Precondition Failed: One or more conditions given in the request header fields evaluated to false when tested on the server.\n */\n Error_Client_412_Precondition_Failed: 412,\n\n /**\n * 413 Payload Too Large: The server is refusing to process a request because the request payload is larger\n * than the server is willing or able to process.\n */\n Error_Client_413_Payload_Too_Large: 413,\n\n /**\n * 414 URI Too Long: The server is refusing to service the request because the URI is longer than the server is willing to interpret.\n */\n Error_Client_414_URI_Too_Long: 414,\n\n /**\n * 415 Unsupported Media Type: The server is refusing to service the request\n * because the entity of the request is in a format not supported by the requested resource for the requested method.\n */\n Error_Client_415_Unsupported_Media_Type: 415,\n\n /**\n * 416 Range Not Satisfiable: The client has asked for a portion of the file, but the server cannot supply that portion.\n */\n Error_Client_416_Range_Not_Satisfiable: 416,\n\n /**\n * 417 Expectation Failed: The server cannot meet the requirements of the Expect request-header field.\n */\n Error_Client_417_Expectation_Failed: 417,\n\n /**\n * 421 Misdirected Request: The request was directed at a server that is not able to produce a response.\n */\n Error_Client_421_Misdirected_Request: 421,\n\n /**\n * 422 Unprocessable Entity: The request was well-formed but was unable to be followed due to semantic errors.\n */\n Error_Client_422_Unprocessable_Entity: 422,\n\n /**\n * 423 Locked: The resource that is being accessed is locked.\n */\n Error_Client_423_Locked: 423,\n\n /**\n * 424 Failed Dependency: The request failed due to a failure of a previous request.\n */\n Error_Client_424_Failed_Dependency: 424,\n\n /**\n * 425 Too Early: The server is unwilling to risk processing a request that might be replayed.\n */\n Error_Client_425_Too_Early: 425,\n\n /**\n * 426 Upgrade Required: The server refuses to perform the request using the current protocol\n * but might be willing to do so after the client upgrades to a different protocol.\n */\n Error_Client_426_Upgrade_Required: 426,\n\n /**\n * 428 Precondition Required: The origin server requires the request to be conditional.\n */\n Error_Client_428_Precondition_Required: 428,\n\n /**\n * 429 Too Many Requests: The user has sent too many requests in a given amount of time (\"rate limiting\").\n */\n Error_Client_429_Too_Many_Requests: 429,\n\n /**\n * 431 Request Header Fields Too Large: The server is unwilling to process the request because its header fields are too large.\n */\n Error_Client_431_Request_Header_Fields_Too_Large: 431,\n\n /**\n * 451 Unavailable For Legal Reasons: The user requests an illegal resource, such as a web page censored by a government.\n */\n Error_Client_451_Unavailable_For_Legal_Reasons: 451,\n\n /**\n * 500 Internal Server Error: A generic error message, given when no more specific message is suitable.\n */\n Error_Server_500_Internal_Server_Error: 500,\n\n /**\n * 501 Not Implemented: The server either does not recognize the request method, or it lacks the ability to fulfill the request.\n */\n Error_Server_501_Not_Implemented: 501,\n\n /**\n * 502 Bad Gateway: The server was acting as a gateway or proxy and received an invalid response from the upstream server.\n */\n Error_Server_502_Bad_Gateway: 502,\n\n /**\n * 503 Service Unavailable: The server is currently unavailable (because it is overloaded or down for maintenance).\n */\n Error_Server_503_Service_Unavailable: 503,\n\n /**\n * 504 Gateway Timeout: The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.\n */\n Error_Server_504_Gateway_Timeout: 504,\n\n /**\n * 505 HTTP Version Not Supported: The server does not support the HTTP protocol version used in the request.\n */\n Error_Server_505_HTTP_Version_Not_Supported: 505,\n\n /**\n * 506 Variant Also Negotiates: Transparent content negotiation for the request results in a circular reference.\n */\n Error_Server_506_Variant_Also_Negotiates: 506,\n\n /**\n * 507 Insufficient Storage: The server is unable to store the representation needed to complete the request.\n */\n Error_Server_507_Insufficient_Storage: 507,\n\n /**\n * 508 Loop Detected: The server detected an infinite loop while processing the request.\n */\n Error_Server_508_Loop_Detected: 508,\n\n /**\n * 510 Not Extended: Further extensions to the request are required for the server to fulfill it.\n */\n Error_Server_510_Not_Extended: 510,\n\n /**\n * 511 Network Authentication Required: The client needs to authenticate to gain network access.\n */\n Error_Server_511_Network_Authentication_Required: 511\n} as const;\n\nexport const HttpStatusMessages = {\n 100: 'Continue',\n 101: 'Switching Protocols',\n 102: 'Processing',\n 103: 'Early Hints',\n 200: 'OK',\n 201: 'Created',\n 202: 'Accepted',\n 203: 'Non-Authoritative Information',\n 204: 'No Content',\n 205: 'Reset Content',\n 206: 'Partial Content',\n 207: 'Multi-Status',\n 208: 'Already Reported',\n 226: 'IM Used',\n 300: 'Multiple Choices',\n 301: 'Moved Permanently',\n 302: 'Found',\n 303: 'See Other',\n 304: 'Not Modified',\n 305: 'Use Proxy',\n 307: 'Temporary Redirect',\n 308: 'Permanent Redirect',\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Failed',\n 413: 'Payload Too Large',\n 414: 'URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: 'I\\'m a Teapot',\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 425: 'Too Early',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 451: 'Unavailable For Legal Reasons',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 506: 'Variant Also Negotiates',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 509: 'Bandwidth Limit Exceeded',\n 510: 'Not Extended',\n 511: 'Network Authentication Required',\n};\n\nexport type HttpStatusCode = keyof typeof HttpStatusMessages;\n", "import {URL} from 'node:url';\n\nimport type {HttpMethod, NativeClientRequest} from './type.js';\n\nexport class NanotronUrl extends URL {\n protected static versionPattern_ = new RegExp('^/v[0-9]+/');\n\n readonly method: HttpMethod;\n readonly debugId: string;\n\n constructor(clientRequest: NativeClientRequest, prefix: `/${string}/` | '/') {\n let url = clientRequest.url ?? '';\n if (prefix !== '/' && url.indexOf(prefix) === 0) {\n url = url.slice(prefix.length - 1); // include `/`\n }\n url = url.replace(NanotronUrl.versionPattern_, '/');\n\n super(url, 'http://hostname/');\n\n this.method = (clientRequest.method ?? 'GET').toUpperCase() as HttpMethod;\n\n this.debugId = `[${this.method}]${this.pathname}`;\n }\n}\n"],
5
+ "mappings": ";;;AAAA,SAAQ,oBAAmB;AAE3B,SAAQ,gBAAAA,eAAc,qBAAoB;;;ACF1C,SAAQ,gBAAAC,qBAAmB;;;ACA3B,SAAQ,oBAAmB;;;ACGpB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA,EAIzB,KAAK;AAAA;AAAA;AAAA;AAAA,EAKL,MAAM;AAAA;AAAA;AAAA;AAAA,EAKN,MAAM;AAAA;AAAA;AAAA;AAAA,EAKN,KAAK;AAAA;AAAA;AAAA;AAAA,EAKL,QAAQ;AAAA;AAAA;AAAA;AAAA,EAKR,SAAS;AAAA;AAAA;AAAA;AAAA,EAKT,SAAS;AAAA;AAAA;AAAA;AAAA,EAKT,OAAO;AAAA;AAAA;AAAA;AAAA,EAKP,OAAO;AACT;AAKO,IAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAI7B,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAKnB,8BAA8B;AAAA;AAAA;AAAA;AAAA,EAK9B,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAKrB,sBAAsB;AAAA;AAAA;AAAA;AAAA,EAKtB,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAKhB,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAKrB,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtB,2CAA2C;AAAA;AAAA;AAAA;AAAA,EAK3C,wBAAwB;AAAA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AAA,EACN,MAAM;AAAA,EACN,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,aAAa;AAAA,IACX,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,IACT,QAAQ;AAAA;AAAA,EACV;AAAA,EACA,QAAQ;AAAA,EACR,WAAW;AAAA;AACb;AAjBK,IAAM,oBAAN;",
6
6
  "names": ["createLogger", "createLogger", "createLogger", "createLogger"]
7
7
  }
package/dist/type.d.ts CHANGED
@@ -53,6 +53,18 @@ export interface DefineRouteOption<TSharedMeta extends DictionaryOpt = Dictionar
53
53
  * @default `1_048_576` (1MiB) or the value set in the server configuration.
54
54
  */
55
55
  bodyLimit?: number;
56
+ /**
57
+ * Add CORS headers
58
+ *
59
+ * @default Api Server Config
60
+ */
61
+ crossOrigin?: {
62
+ enable: boolean;
63
+ origin: string;
64
+ methods: string;
65
+ headers: string;
66
+ maxAge: string | number;
67
+ };
56
68
  }
57
69
  /**
58
70
  * Represents the collection of HTTP response headers.
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAC,sBAAsB,EAAC,MAAM,0BAA0B,CAAC;AACrE,OAAO,KAAK,EAAC,eAAe,EAAE,cAAc,EAAC,MAAM,WAAW,CAAC;AAE/D,OAAO,QAAQ,MAAM,CAAC;IACpB,UAAU,mBAAmB;QAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B;CACF;AAED,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,YAAY,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,C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- "version": "4.6.0",
3
+ "version": "4.8.0",
4
4
  "description": "Nanotron: Your Lightweight, High-Performance Micro/Nano Service Framework. Nanotron is designed for building blazingly fast and efficient microservices and APIs. Its minimalist approach and focus on performance make it ideal for resource-constrained environments and scenarios where every millisecond counts.",
5
5
  "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
6
6
  "keywords": [
@@ -68,5 +68,5 @@
68
68
  "jest": "^29.7.0",
69
69
  "typescript": "^5.6.3"
70
70
  },
71
- "gitHead": "2c680281d1a01aa734dc2867c9d41be8f1848182"
71
+ "gitHead": "7155ae10b06476671c6f9f583d053919a1c40f01"
72
72
  }