@expressots/adapter-express 3.0.0 → 4.0.0-preview.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -96
- package/lib/CHANGELOG.md +31 -5
- package/lib/README.md +39 -96
- package/lib/cjs/adapter-express/application-express.base.js +3 -1
- package/lib/cjs/adapter-express/application-express.js +1049 -85
- package/lib/cjs/adapter-express/express-utils/conditional-middleware.js +102 -0
- package/lib/cjs/adapter-express/express-utils/constants.js +17 -0
- package/lib/cjs/adapter-express/express-utils/content-negotiation-decorators.js +129 -0
- package/lib/cjs/adapter-express/express-utils/decorators.js +186 -49
- package/lib/cjs/adapter-express/express-utils/exception-filter-decorators.js +11 -0
- package/lib/cjs/adapter-express/express-utils/guard-context-factory.js +84 -0
- package/lib/cjs/adapter-express/express-utils/guard-middleware.js +115 -0
- package/lib/cjs/adapter-express/express-utils/guard-utils.js +18 -0
- package/lib/cjs/adapter-express/express-utils/http-context-store.js +15 -0
- package/lib/cjs/adapter-express/express-utils/http-status-middleware.js +37 -2
- package/lib/cjs/adapter-express/express-utils/index.js +67 -1
- package/lib/cjs/adapter-express/express-utils/interceptor-middleware.js +132 -0
- package/lib/cjs/adapter-express/express-utils/inversify-express-server.js +810 -63
- package/lib/cjs/adapter-express/express-utils/lazy-module-middleware.js +241 -0
- package/lib/cjs/adapter-express/express-utils/middleware-composition.js +95 -0
- package/lib/cjs/adapter-express/express-utils/permission-preloader.middleware.js +48 -0
- package/lib/cjs/adapter-express/express-utils/route-constraints.js +95 -0
- package/lib/cjs/adapter-express/express-utils/scope-extractor.interface.js +2 -0
- package/lib/cjs/adapter-express/express-utils/scope-extractor.js +66 -0
- package/lib/cjs/adapter-express/express-utils/setup-authorization.js +71 -0
- package/lib/cjs/adapter-express/express-utils/setup-event-system.js +113 -0
- package/lib/cjs/adapter-express/express-utils/setup-interceptors.js +103 -0
- package/lib/cjs/adapter-express/express-utils/setup-lazy-loading.js +228 -0
- package/lib/cjs/adapter-express/express-utils/utils.js +30 -12
- package/lib/cjs/adapter-express/express-utils/validation-decorators.js +205 -0
- package/lib/cjs/adapter-express/express-utils/validation-service.js +252 -0
- package/lib/cjs/adapter-express/index.js +7 -5
- package/lib/cjs/adapter-express/micro-api/application-express-micro-route.js +31 -1
- package/lib/cjs/adapter-express/micro-api/application-express-micro.js +11 -37
- package/lib/cjs/adapter-express/micro-api/gateway/circuit-breaker.js +174 -0
- package/lib/cjs/adapter-express/micro-api/gateway/index.js +11 -0
- package/lib/cjs/adapter-express/micro-api/gateway/service-proxy.js +214 -0
- package/lib/cjs/adapter-express/micro-api/index.js +27 -3
- package/lib/cjs/adapter-express/micro-api/micro.js +217 -0
- package/lib/cjs/adapter-express/micro-api/queue/index.js +8 -0
- package/lib/cjs/adapter-express/micro-api/queue/queue.interface.js +2 -0
- package/lib/cjs/adapter-express/micro-api/queue/rabbitmq-consumer.js +255 -0
- package/lib/cjs/adapter-express/micro-api/serverless/aws-lambda.adapter.js +183 -0
- package/lib/cjs/adapter-express/micro-api/serverless/cloudflare.adapter.js +158 -0
- package/lib/cjs/adapter-express/micro-api/serverless/index.js +12 -0
- package/lib/cjs/adapter-express/micro-api/serverless/vercel.adapter.js +102 -0
- package/lib/cjs/adapter-express/micro-api/service-mesh/index.js +10 -0
- package/lib/cjs/adapter-express/micro-api/service-mesh/service-client.js +194 -0
- package/lib/cjs/adapter-express/micro-api/service-mesh/service-discovery.js +261 -0
- package/lib/cjs/adapter-express/middleware/index.js +21 -0
- package/lib/cjs/adapter-express/middleware/request-logging.middleware.js +244 -0
- package/lib/cjs/adapter-express/render/engine.js +15 -15
- package/lib/cjs/adapter-express/render/index.js +5 -0
- package/lib/cjs/adapter-express/studio/index.js +9 -0
- package/lib/cjs/adapter-express/studio/studio-integration.js +214 -0
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/types/adapter-express/application-express.base.d.ts +20 -7
- package/lib/cjs/types/adapter-express/application-express.d.ts +273 -32
- package/lib/cjs/types/adapter-express/express-utils/base-middleware.d.ts +2 -2
- package/lib/cjs/types/adapter-express/express-utils/conditional-middleware.d.ts +97 -0
- package/lib/cjs/types/adapter-express/express-utils/constants.d.ts +13 -0
- package/lib/cjs/types/adapter-express/express-utils/content-negotiation-decorators.d.ts +94 -0
- package/lib/cjs/types/adapter-express/express-utils/decorators.d.ts +54 -6
- package/lib/cjs/types/adapter-express/express-utils/exception-filter-decorators.d.ts +6 -0
- package/lib/cjs/types/adapter-express/express-utils/guard-context-factory.d.ts +17 -0
- package/lib/cjs/types/adapter-express/express-utils/guard-middleware.d.ts +22 -0
- package/lib/cjs/types/adapter-express/express-utils/guard-utils.d.ts +11 -0
- package/lib/cjs/types/adapter-express/express-utils/http-context-store.d.ts +20 -0
- package/lib/cjs/types/adapter-express/express-utils/httpResponseMessage.d.ts +1 -1
- package/lib/cjs/types/adapter-express/express-utils/index.d.ts +30 -2
- package/lib/cjs/types/adapter-express/express-utils/interceptor-middleware.d.ts +40 -0
- package/lib/cjs/types/adapter-express/express-utils/interfaces.d.ts +42 -5
- package/lib/cjs/types/adapter-express/express-utils/inversify-express-server.d.ts +114 -2
- package/lib/cjs/types/adapter-express/express-utils/lazy-module-middleware.d.ts +122 -0
- package/lib/cjs/types/adapter-express/express-utils/middleware-composition.d.ts +85 -0
- package/lib/cjs/types/adapter-express/express-utils/permission-preloader.middleware.d.ts +10 -0
- package/lib/cjs/types/adapter-express/express-utils/route-constraints.d.ts +89 -0
- package/lib/cjs/types/adapter-express/express-utils/scope-extractor.d.ts +21 -0
- package/lib/cjs/types/adapter-express/express-utils/scope-extractor.interface.d.ts +12 -0
- package/lib/cjs/types/adapter-express/express-utils/setup-authorization.d.ts +34 -0
- package/lib/cjs/types/adapter-express/express-utils/setup-event-system.d.ts +118 -0
- package/lib/cjs/types/adapter-express/express-utils/setup-interceptors.d.ts +115 -0
- package/lib/cjs/types/adapter-express/express-utils/setup-lazy-loading.d.ts +123 -0
- package/lib/cjs/types/adapter-express/express-utils/utils.d.ts +17 -2
- package/lib/cjs/types/adapter-express/express-utils/validation-decorators.d.ts +145 -0
- package/lib/cjs/types/adapter-express/express-utils/validation-service.d.ts +88 -0
- package/lib/cjs/types/adapter-express/index.d.ts +6 -4
- package/lib/cjs/types/adapter-express/micro-api/application-express-micro-route.d.ts +25 -14
- package/lib/cjs/types/adapter-express/micro-api/application-express-micro.d.ts +3 -10
- package/lib/cjs/types/adapter-express/micro-api/gateway/circuit-breaker.d.ts +111 -0
- package/lib/cjs/types/adapter-express/micro-api/gateway/index.d.ts +5 -0
- package/lib/cjs/types/adapter-express/micro-api/gateway/service-proxy.d.ts +83 -0
- package/lib/cjs/types/adapter-express/micro-api/index.d.ts +7 -1
- package/lib/cjs/types/adapter-express/micro-api/micro.d.ts +66 -0
- package/lib/cjs/types/adapter-express/micro-api/queue/index.d.ts +5 -0
- package/lib/cjs/types/adapter-express/micro-api/queue/queue.interface.d.ts +60 -0
- package/lib/cjs/types/adapter-express/micro-api/queue/rabbitmq-consumer.d.ts +86 -0
- package/lib/cjs/types/adapter-express/micro-api/serverless/aws-lambda.adapter.d.ts +77 -0
- package/lib/cjs/types/adapter-express/micro-api/serverless/cloudflare.adapter.d.ts +64 -0
- package/lib/cjs/types/adapter-express/micro-api/serverless/index.d.ts +6 -0
- package/lib/cjs/types/adapter-express/micro-api/serverless/vercel.adapter.d.ts +56 -0
- package/lib/cjs/types/adapter-express/micro-api/service-mesh/index.d.ts +5 -0
- package/lib/cjs/types/adapter-express/micro-api/service-mesh/service-client.d.ts +122 -0
- package/lib/cjs/types/adapter-express/micro-api/service-mesh/service-discovery.d.ts +150 -0
- package/lib/cjs/types/adapter-express/middleware/index.d.ts +5 -0
- package/lib/cjs/types/adapter-express/middleware/request-logging.middleware.d.ts +65 -0
- package/lib/cjs/types/adapter-express/render/index.d.ts +1 -0
- package/lib/cjs/types/adapter-express/studio/index.d.ts +1 -0
- package/lib/cjs/types/adapter-express/studio/studio-integration.d.ts +92 -0
- package/lib/cjs/types/index.d.ts +1 -1
- package/lib/esm/adapter-express/application-express.base.js +24 -0
- package/lib/esm/adapter-express/application-express.js +1300 -0
- package/lib/esm/adapter-express/application-express.types.js +1 -0
- package/lib/esm/adapter-express/express-utils/base-middleware.js +19 -0
- package/lib/esm/adapter-express/express-utils/conditional-middleware.js +96 -0
- package/lib/esm/adapter-express/express-utils/constants.js +63 -0
- package/lib/esm/adapter-express/express-utils/content/httpContent.js +6 -0
- package/lib/esm/adapter-express/express-utils/content-negotiation-decorators.js +120 -0
- package/lib/esm/adapter-express/express-utils/decorators.js +575 -0
- package/lib/esm/adapter-express/express-utils/exception-filter-decorators.js +6 -0
- package/lib/esm/adapter-express/express-utils/guard-context-factory.js +83 -0
- package/lib/esm/adapter-express/express-utils/guard-middleware.js +115 -0
- package/lib/esm/adapter-express/express-utils/guard-utils.js +14 -0
- package/lib/esm/adapter-express/express-utils/http-context-store.js +10 -0
- package/lib/esm/adapter-express/express-utils/http-status-middleware.js +116 -0
- package/lib/esm/adapter-express/express-utils/httpResponseMessage.js +29 -0
- package/lib/esm/adapter-express/express-utils/index.js +24 -0
- package/lib/esm/adapter-express/express-utils/interceptor-middleware.js +130 -0
- package/lib/esm/adapter-express/express-utils/interfaces.js +1 -0
- package/lib/esm/adapter-express/express-utils/inversify-express-server.js +1031 -0
- package/lib/esm/adapter-express/express-utils/lazy-module-middleware.js +236 -0
- package/lib/esm/adapter-express/express-utils/middleware-composition.js +89 -0
- package/lib/esm/adapter-express/express-utils/permission-preloader.middleware.js +45 -0
- package/lib/esm/adapter-express/express-utils/resolver-multer.js +30 -0
- package/lib/esm/adapter-express/express-utils/route-constraints.js +91 -0
- package/lib/esm/adapter-express/express-utils/scope-extractor.interface.js +1 -0
- package/lib/esm/adapter-express/express-utils/scope-extractor.js +63 -0
- package/lib/esm/adapter-express/express-utils/setup-authorization.js +68 -0
- package/lib/esm/adapter-express/express-utils/setup-event-system.js +110 -0
- package/lib/esm/adapter-express/express-utils/setup-interceptors.js +100 -0
- package/lib/esm/adapter-express/express-utils/setup-lazy-loading.js +225 -0
- package/lib/esm/adapter-express/express-utils/utils.js +68 -0
- package/lib/esm/adapter-express/express-utils/validation-decorators.js +199 -0
- package/lib/esm/adapter-express/express-utils/validation-service.js +251 -0
- package/lib/esm/adapter-express/index.js +7 -0
- package/lib/esm/adapter-express/micro-api/application-express-micro-container.js +48 -0
- package/lib/esm/adapter-express/micro-api/application-express-micro-route.js +128 -0
- package/lib/esm/adapter-express/micro-api/application-express-micro.js +161 -0
- package/lib/esm/adapter-express/micro-api/gateway/circuit-breaker.js +174 -0
- package/lib/esm/adapter-express/micro-api/gateway/index.js +5 -0
- package/lib/esm/adapter-express/micro-api/gateway/service-proxy.js +210 -0
- package/lib/esm/adapter-express/micro-api/index.js +10 -0
- package/lib/esm/adapter-express/micro-api/micro.js +211 -0
- package/lib/esm/adapter-express/micro-api/queue/index.js +4 -0
- package/lib/esm/adapter-express/micro-api/queue/queue.interface.js +1 -0
- package/lib/esm/adapter-express/micro-api/queue/rabbitmq-consumer.js +229 -0
- package/lib/esm/adapter-express/micro-api/serverless/aws-lambda.adapter.js +180 -0
- package/lib/esm/adapter-express/micro-api/serverless/cloudflare.adapter.js +155 -0
- package/lib/esm/adapter-express/micro-api/serverless/index.js +6 -0
- package/lib/esm/adapter-express/micro-api/serverless/vercel.adapter.js +99 -0
- package/lib/esm/adapter-express/micro-api/service-mesh/index.js +5 -0
- package/lib/esm/adapter-express/micro-api/service-mesh/service-client.js +191 -0
- package/lib/esm/adapter-express/micro-api/service-mesh/service-discovery.js +259 -0
- package/lib/esm/adapter-express/middleware/index.js +5 -0
- package/lib/esm/adapter-express/middleware/request-logging.middleware.js +239 -0
- package/lib/esm/adapter-express/render/constants.js +37 -0
- package/lib/esm/adapter-express/render/engine.js +51 -0
- package/lib/esm/adapter-express/render/index.js +1 -0
- package/lib/esm/adapter-express/render/resolve-render.js +30 -0
- package/lib/esm/adapter-express/studio/index.js +1 -0
- package/lib/esm/adapter-express/studio/studio-integration.js +184 -0
- package/lib/esm/index.mjs +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/types/adapter-express/application-express.base.d.ts +77 -0
- package/lib/esm/types/adapter-express/application-express.d.ts +411 -0
- package/lib/esm/types/adapter-express/application-express.types.d.ts +23 -0
- package/lib/esm/types/adapter-express/express-utils/base-middleware.d.ts +8 -0
- package/lib/esm/types/adapter-express/express-utils/conditional-middleware.d.ts +97 -0
- package/lib/esm/types/adapter-express/express-utils/constants.d.ts +57 -0
- package/lib/esm/types/adapter-express/express-utils/content/httpContent.d.ts +6 -0
- package/lib/esm/types/adapter-express/express-utils/content-negotiation-decorators.d.ts +94 -0
- package/lib/esm/types/adapter-express/express-utils/decorators.d.ts +257 -0
- package/lib/esm/types/adapter-express/express-utils/exception-filter-decorators.d.ts +6 -0
- package/lib/esm/types/adapter-express/express-utils/guard-context-factory.d.ts +17 -0
- package/lib/esm/types/adapter-express/express-utils/guard-middleware.d.ts +22 -0
- package/lib/esm/types/adapter-express/express-utils/guard-utils.d.ts +11 -0
- package/lib/esm/types/adapter-express/express-utils/http-context-store.d.ts +20 -0
- package/lib/esm/types/adapter-express/express-utils/http-status-middleware.d.ts +26 -0
- package/lib/esm/types/adapter-express/express-utils/httpResponseMessage.d.ts +14 -0
- package/lib/esm/types/adapter-express/express-utils/index.d.ts +30 -0
- package/lib/esm/types/adapter-express/express-utils/interceptor-middleware.d.ts +40 -0
- package/lib/esm/types/adapter-express/express-utils/interfaces.d.ts +115 -0
- package/lib/esm/types/adapter-express/express-utils/inversify-express-server.d.ts +172 -0
- package/lib/esm/types/adapter-express/express-utils/lazy-module-middleware.d.ts +122 -0
- package/lib/esm/types/adapter-express/express-utils/middleware-composition.d.ts +85 -0
- package/lib/esm/types/adapter-express/express-utils/permission-preloader.middleware.d.ts +10 -0
- package/lib/esm/types/adapter-express/express-utils/resolver-multer.d.ts +7 -0
- package/lib/esm/types/adapter-express/express-utils/route-constraints.d.ts +89 -0
- package/lib/esm/types/adapter-express/express-utils/scope-extractor.d.ts +21 -0
- package/lib/esm/types/adapter-express/express-utils/scope-extractor.interface.d.ts +12 -0
- package/lib/esm/types/adapter-express/express-utils/setup-authorization.d.ts +34 -0
- package/lib/esm/types/adapter-express/express-utils/setup-event-system.d.ts +118 -0
- package/lib/esm/types/adapter-express/express-utils/setup-interceptors.d.ts +115 -0
- package/lib/esm/types/adapter-express/express-utils/setup-lazy-loading.d.ts +123 -0
- package/lib/esm/types/adapter-express/express-utils/utils.d.ts +24 -0
- package/lib/esm/types/adapter-express/express-utils/validation-decorators.d.ts +145 -0
- package/lib/esm/types/adapter-express/express-utils/validation-service.d.ts +88 -0
- package/lib/esm/types/adapter-express/index.d.ts +7 -0
- package/lib/esm/types/adapter-express/micro-api/application-express-micro-container.d.ts +47 -0
- package/lib/esm/types/adapter-express/micro-api/application-express-micro-route.d.ts +104 -0
- package/lib/esm/types/adapter-express/micro-api/application-express-micro.d.ts +72 -0
- package/lib/esm/types/adapter-express/micro-api/gateway/circuit-breaker.d.ts +111 -0
- package/lib/esm/types/adapter-express/micro-api/gateway/index.d.ts +5 -0
- package/lib/esm/types/adapter-express/micro-api/gateway/service-proxy.d.ts +83 -0
- package/lib/esm/types/adapter-express/micro-api/index.d.ts +7 -0
- package/lib/esm/types/adapter-express/micro-api/micro.d.ts +66 -0
- package/lib/esm/types/adapter-express/micro-api/queue/index.d.ts +5 -0
- package/lib/esm/types/adapter-express/micro-api/queue/queue.interface.d.ts +60 -0
- package/lib/esm/types/adapter-express/micro-api/queue/rabbitmq-consumer.d.ts +86 -0
- package/lib/esm/types/adapter-express/micro-api/serverless/aws-lambda.adapter.d.ts +77 -0
- package/lib/esm/types/adapter-express/micro-api/serverless/cloudflare.adapter.d.ts +64 -0
- package/lib/esm/types/adapter-express/micro-api/serverless/index.d.ts +6 -0
- package/lib/esm/types/adapter-express/micro-api/serverless/vercel.adapter.d.ts +56 -0
- package/lib/esm/types/adapter-express/micro-api/service-mesh/index.d.ts +5 -0
- package/lib/esm/types/adapter-express/micro-api/service-mesh/service-client.d.ts +122 -0
- package/lib/esm/types/adapter-express/micro-api/service-mesh/service-discovery.d.ts +150 -0
- package/lib/esm/types/adapter-express/middleware/index.d.ts +5 -0
- package/lib/esm/types/adapter-express/middleware/request-logging.middleware.d.ts +65 -0
- package/lib/esm/types/adapter-express/render/constants.d.ts +26 -0
- package/lib/esm/types/adapter-express/render/engine.d.ts +20 -0
- package/lib/esm/types/adapter-express/render/index.d.ts +5 -0
- package/lib/esm/types/adapter-express/render/resolve-render.d.ts +7 -0
- package/lib/esm/types/adapter-express/studio/index.d.ts +1 -0
- package/lib/esm/types/adapter-express/studio/studio-integration.d.ts +92 -0
- package/lib/esm/types/index.d.ts +1 -0
- package/lib/package.json +156 -146
- package/package.json +156 -146
- package/lib/cjs/di/di.interfaces.js +0 -10
- package/lib/cjs/types/di/di.interfaces.d.ts +0 -289
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.RabbitMQConsumer = void 0;
|
|
27
|
+
/**
|
|
28
|
+
* Load amqplib dynamically to avoid requiring it as a dependency
|
|
29
|
+
*/
|
|
30
|
+
async function loadAmqpLib() {
|
|
31
|
+
try {
|
|
32
|
+
// `amqplib` is an OPTIONAL peer dep - it is intentionally not installed
|
|
33
|
+
// in this package's devDependencies. We route the specifier through a
|
|
34
|
+
// variable so TypeScript does not try to statically resolve it during
|
|
35
|
+
// build (TS treats variable-typed specifiers in `await import(...)` as
|
|
36
|
+
// `any` and skips the resolution check). Resolution happens at runtime
|
|
37
|
+
// in user apps that have actually installed amqplib.
|
|
38
|
+
const specifier = "amqplib";
|
|
39
|
+
const amqp = (await Promise.resolve(`${specifier}`).then(s => __importStar(require(s))));
|
|
40
|
+
return amqp;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
throw new Error("amqplib is not installed. Install it with: npm install amqplib @types/amqplib");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* RabbitMQ Consumer - Message queue consumer for RabbitMQ.
|
|
48
|
+
*
|
|
49
|
+
* Features:
|
|
50
|
+
* - Message consumption with handlers
|
|
51
|
+
* - Message publishing
|
|
52
|
+
* - Exchange support
|
|
53
|
+
* - Automatic reconnection
|
|
54
|
+
* - Prefetch control
|
|
55
|
+
* - Dead letter queue support
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const orderQueue = new RabbitMQConsumer({
|
|
60
|
+
* url: process.env.RABBITMQ_URL,
|
|
61
|
+
* queue: "orders",
|
|
62
|
+
* prefetch: 10,
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Start consuming
|
|
66
|
+
* await orderQueue.consume(async (message) => {
|
|
67
|
+
* const order = message.body;
|
|
68
|
+
* console.log("Processing order:", order.id);
|
|
69
|
+
* await processOrder(order);
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* // Publish from HTTP endpoint
|
|
73
|
+
* app.Route.post("/orders", async (req, res) => {
|
|
74
|
+
* await orderQueue.publish(req.body);
|
|
75
|
+
* res.status(202).json({ message: "Order queued" });
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* // Graceful shutdown
|
|
79
|
+
* process.on("SIGTERM", async () => {
|
|
80
|
+
* await orderQueue.close();
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* Note: This implementation requires the 'amqplib' package.
|
|
85
|
+
* Install with: npm install amqplib @types/amqplib
|
|
86
|
+
*/
|
|
87
|
+
class RabbitMQConsumer {
|
|
88
|
+
constructor(config) {
|
|
89
|
+
// Using 'any' for AMQP types since amqplib is an optional peer dependency
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
91
|
+
this.connection = null;
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
93
|
+
this.channel = null;
|
|
94
|
+
this.stats = {
|
|
95
|
+
messagesReceived: 0,
|
|
96
|
+
messagesProcessed: 0,
|
|
97
|
+
messagesFailed: 0,
|
|
98
|
+
messagesPublished: 0,
|
|
99
|
+
isConnected: false,
|
|
100
|
+
};
|
|
101
|
+
this.config = {
|
|
102
|
+
queue: config.queue,
|
|
103
|
+
url: config.url,
|
|
104
|
+
exchange: config.exchange ?? "",
|
|
105
|
+
exchangeType: config.exchangeType ?? "direct",
|
|
106
|
+
routingKey: config.routingKey ?? config.queue,
|
|
107
|
+
prefetch: config.prefetch ?? 1,
|
|
108
|
+
durable: config.durable ?? true,
|
|
109
|
+
concurrency: config.concurrency ?? 1,
|
|
110
|
+
autoAck: config.autoAck ?? true,
|
|
111
|
+
debug: config.debug ?? false,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Connect to RabbitMQ
|
|
116
|
+
*/
|
|
117
|
+
async connect() {
|
|
118
|
+
if (this.connection)
|
|
119
|
+
return;
|
|
120
|
+
try {
|
|
121
|
+
const amqp = await loadAmqpLib();
|
|
122
|
+
this.connection = await amqp.connect(this.config.url);
|
|
123
|
+
this.channel = await this.connection.createChannel();
|
|
124
|
+
// Set prefetch
|
|
125
|
+
await this.channel.prefetch(this.config.prefetch);
|
|
126
|
+
// Declare queue
|
|
127
|
+
await this.channel.assertQueue(this.config.queue, {
|
|
128
|
+
durable: this.config.durable,
|
|
129
|
+
});
|
|
130
|
+
// Declare exchange if configured
|
|
131
|
+
if (this.config.exchange) {
|
|
132
|
+
await this.channel.assertExchange(this.config.exchange, this.config.exchangeType, {
|
|
133
|
+
durable: true,
|
|
134
|
+
});
|
|
135
|
+
// Bind queue to exchange
|
|
136
|
+
await this.channel.bindQueue(this.config.queue, this.config.exchange, this.config.routingKey);
|
|
137
|
+
}
|
|
138
|
+
this.stats.isConnected = true;
|
|
139
|
+
if (this.config.debug) {
|
|
140
|
+
console.log(`[RabbitMQ] Connected to ${this.config.url}, queue: ${this.config.queue}`);
|
|
141
|
+
}
|
|
142
|
+
// Handle connection close
|
|
143
|
+
this.connection.on("close", () => {
|
|
144
|
+
this.stats.isConnected = false;
|
|
145
|
+
console.log("[RabbitMQ] Connection closed");
|
|
146
|
+
});
|
|
147
|
+
this.connection.on("error", (err) => {
|
|
148
|
+
console.error("[RabbitMQ] Connection error:", err);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
console.error("[RabbitMQ] Failed to connect:", error);
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Start consuming messages
|
|
158
|
+
*/
|
|
159
|
+
async consume(handler) {
|
|
160
|
+
await this.connect();
|
|
161
|
+
if (!this.channel) {
|
|
162
|
+
throw new Error("Channel not initialized");
|
|
163
|
+
}
|
|
164
|
+
await this.channel.consume(this.config.queue,
|
|
165
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
166
|
+
async (msg) => {
|
|
167
|
+
if (!msg)
|
|
168
|
+
return;
|
|
169
|
+
this.stats.messagesReceived++;
|
|
170
|
+
this.stats.lastMessageAt = new Date();
|
|
171
|
+
try {
|
|
172
|
+
// Parse message
|
|
173
|
+
const body = JSON.parse(msg.content.toString());
|
|
174
|
+
const queueMessage = {
|
|
175
|
+
id: msg.properties.messageId || Date.now().toString(36),
|
|
176
|
+
body,
|
|
177
|
+
headers: msg.properties.headers,
|
|
178
|
+
timestamp: new Date(msg.properties.timestamp || Date.now()),
|
|
179
|
+
receiveCount: msg.properties.headers?.["x-delivery-count"] || 1,
|
|
180
|
+
raw: msg,
|
|
181
|
+
};
|
|
182
|
+
if (this.config.debug) {
|
|
183
|
+
console.log(`[RabbitMQ] Received message:`, queueMessage.id);
|
|
184
|
+
}
|
|
185
|
+
// Process message
|
|
186
|
+
await handler(queueMessage);
|
|
187
|
+
this.stats.messagesProcessed++;
|
|
188
|
+
// Acknowledge
|
|
189
|
+
if (!this.config.autoAck && this.channel) {
|
|
190
|
+
this.channel.ack(msg);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
this.stats.messagesFailed++;
|
|
195
|
+
console.error("[RabbitMQ] Message processing failed:", error);
|
|
196
|
+
// Reject and requeue if not auto-ack
|
|
197
|
+
if (!this.config.autoAck && this.channel) {
|
|
198
|
+
this.channel.nack(msg, false, true);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}, { noAck: this.config.autoAck });
|
|
202
|
+
if (this.config.debug) {
|
|
203
|
+
console.log(`[RabbitMQ] Consuming from ${this.config.queue}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Publish a message to the queue
|
|
208
|
+
*/
|
|
209
|
+
async publish(message) {
|
|
210
|
+
await this.connect();
|
|
211
|
+
if (!this.channel) {
|
|
212
|
+
throw new Error("Channel not initialized");
|
|
213
|
+
}
|
|
214
|
+
const content = Buffer.from(JSON.stringify(message));
|
|
215
|
+
const properties = {
|
|
216
|
+
messageId: Date.now().toString(36),
|
|
217
|
+
timestamp: Date.now(),
|
|
218
|
+
contentType: "application/json",
|
|
219
|
+
};
|
|
220
|
+
if (this.config.exchange) {
|
|
221
|
+
this.channel.publish(this.config.exchange, this.config.routingKey, content, properties);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
this.channel.sendToQueue(this.config.queue, content, properties);
|
|
225
|
+
}
|
|
226
|
+
this.stats.messagesPublished++;
|
|
227
|
+
if (this.config.debug) {
|
|
228
|
+
console.log(`[RabbitMQ] Published message to ${this.config.queue}`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Close the connection
|
|
233
|
+
*/
|
|
234
|
+
async close() {
|
|
235
|
+
if (this.channel) {
|
|
236
|
+
await this.channel.close();
|
|
237
|
+
this.channel = null;
|
|
238
|
+
}
|
|
239
|
+
if (this.connection) {
|
|
240
|
+
await this.connection.close();
|
|
241
|
+
this.connection = null;
|
|
242
|
+
}
|
|
243
|
+
this.stats.isConnected = false;
|
|
244
|
+
if (this.config.debug) {
|
|
245
|
+
console.log("[RabbitMQ] Connection closed");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Get consumer statistics
|
|
250
|
+
*/
|
|
251
|
+
getStats() {
|
|
252
|
+
return { ...this.stats };
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
exports.RabbitMQConsumer = RabbitMQConsumer;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AWS Lambda Adapter for ExpressoTS Micro API
|
|
4
|
+
*
|
|
5
|
+
* Converts Lambda events to Express requests and responses.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.awsLambdaAdapter = awsLambdaAdapter;
|
|
9
|
+
/**
|
|
10
|
+
* Create an AWS Lambda handler from an Express app
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createMicroAPI, awsLambdaAdapter } from "@expressots/adapter-express";
|
|
15
|
+
*
|
|
16
|
+
* const microAPI = createMicroAPI();
|
|
17
|
+
* const app = microAPI.build();
|
|
18
|
+
*
|
|
19
|
+
* app.Middleware.parse();
|
|
20
|
+
* app.Route.get("/", (req, res) => res.json({ message: "Hello Lambda!" }));
|
|
21
|
+
*
|
|
22
|
+
* export const handler = awsLambdaAdapter(app);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function awsLambdaAdapter(app, config) {
|
|
26
|
+
const expressApp = "getExpressApp" in app && app.getExpressApp ? app.getExpressApp() : app;
|
|
27
|
+
const binaryTypes = config?.binaryContentTypes ?? [
|
|
28
|
+
"application/octet-stream",
|
|
29
|
+
"image/*",
|
|
30
|
+
"audio/*",
|
|
31
|
+
"video/*",
|
|
32
|
+
"font/*",
|
|
33
|
+
];
|
|
34
|
+
const debug = config?.debug ?? false;
|
|
35
|
+
return async (event, context) => {
|
|
36
|
+
if (debug) {
|
|
37
|
+
console.log("[Lambda] Event:", JSON.stringify(event, null, 2));
|
|
38
|
+
}
|
|
39
|
+
// Parse body
|
|
40
|
+
let body;
|
|
41
|
+
if (event.body) {
|
|
42
|
+
let rawBody;
|
|
43
|
+
if (event.isBase64Encoded) {
|
|
44
|
+
rawBody = Buffer.from(event.body, "base64");
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
rawBody = event.body;
|
|
48
|
+
}
|
|
49
|
+
// Parse JSON body if content-type is application/json
|
|
50
|
+
const contentType = event.headers?.["content-type"] || event.headers?.["Content-Type"] || "";
|
|
51
|
+
if (contentType.includes("application/json")) {
|
|
52
|
+
try {
|
|
53
|
+
const bodyStr = Buffer.isBuffer(rawBody) ? rawBody.toString("utf8") : rawBody;
|
|
54
|
+
body = JSON.parse(bodyStr);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Keep as raw if JSON parsing fails
|
|
58
|
+
body = rawBody;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
body = rawBody;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Build request URL
|
|
66
|
+
const queryString = event.queryStringParameters
|
|
67
|
+
? "?" +
|
|
68
|
+
Object.entries(event.queryStringParameters)
|
|
69
|
+
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
|
|
70
|
+
.join("&")
|
|
71
|
+
: "";
|
|
72
|
+
const url = event.path + queryString;
|
|
73
|
+
// Build headers
|
|
74
|
+
const headers = {
|
|
75
|
+
...event.headers,
|
|
76
|
+
};
|
|
77
|
+
// Add Lambda context to headers
|
|
78
|
+
headers["x-lambda-request-id"] = context.awsRequestId;
|
|
79
|
+
headers["x-lambda-function"] = context.functionName;
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
81
|
+
return new Promise((resolve, _reject) => {
|
|
82
|
+
// Create mock Express-compatible request object
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
84
|
+
const req = {
|
|
85
|
+
method: event.httpMethod,
|
|
86
|
+
url,
|
|
87
|
+
path: event.path,
|
|
88
|
+
headers,
|
|
89
|
+
body,
|
|
90
|
+
query: event.queryStringParameters || {},
|
|
91
|
+
params: {},
|
|
92
|
+
lambda: { event, context },
|
|
93
|
+
get: (name) => headers[name.toLowerCase()],
|
|
94
|
+
};
|
|
95
|
+
// Create mock Express-compatible response object
|
|
96
|
+
const chunks = [];
|
|
97
|
+
const responseHeaders = {};
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
|
+
const res = {
|
|
100
|
+
statusCode: 200,
|
|
101
|
+
setHeader: (name, value) => {
|
|
102
|
+
responseHeaders[name.toLowerCase()] = value;
|
|
103
|
+
},
|
|
104
|
+
getHeader: (name) => responseHeaders[name.toLowerCase()],
|
|
105
|
+
write: (chunk) => {
|
|
106
|
+
chunks.push(Buffer.from(chunk));
|
|
107
|
+
},
|
|
108
|
+
end: (chunk) => {
|
|
109
|
+
if (chunk) {
|
|
110
|
+
chunks.push(Buffer.from(chunk));
|
|
111
|
+
}
|
|
112
|
+
const bodyBuffer = Buffer.concat(chunks);
|
|
113
|
+
const contentType = responseHeaders["content-type"] || "";
|
|
114
|
+
const isBinary = binaryTypes.some((type) => {
|
|
115
|
+
if (type.endsWith("/*")) {
|
|
116
|
+
return contentType.startsWith(type.replace("/*", "/"));
|
|
117
|
+
}
|
|
118
|
+
return contentType === type;
|
|
119
|
+
});
|
|
120
|
+
const response = {
|
|
121
|
+
statusCode: res.statusCode,
|
|
122
|
+
headers: responseHeaders,
|
|
123
|
+
body: isBinary ? bodyBuffer.toString("base64") : bodyBuffer.toString("utf8"),
|
|
124
|
+
isBase64Encoded: isBinary,
|
|
125
|
+
};
|
|
126
|
+
if (debug) {
|
|
127
|
+
console.log("[Lambda] Response:", {
|
|
128
|
+
statusCode: response.statusCode,
|
|
129
|
+
headers: response.headers,
|
|
130
|
+
bodyLength: response.body.length,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
resolve(response);
|
|
134
|
+
},
|
|
135
|
+
status: (code) => {
|
|
136
|
+
res.statusCode = code;
|
|
137
|
+
return res;
|
|
138
|
+
},
|
|
139
|
+
json: (data) => {
|
|
140
|
+
res.setHeader("content-type", "application/json");
|
|
141
|
+
res.end(JSON.stringify(data));
|
|
142
|
+
},
|
|
143
|
+
send: (data) => {
|
|
144
|
+
if (typeof data === "string") {
|
|
145
|
+
res.setHeader("content-type", "text/html");
|
|
146
|
+
res.end(data);
|
|
147
|
+
}
|
|
148
|
+
else if (Buffer.isBuffer(data)) {
|
|
149
|
+
res.end(data);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
res.json(data);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
// Handle request through Express
|
|
157
|
+
try {
|
|
158
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
159
|
+
expressApp(req, res, (err) => {
|
|
160
|
+
if (err) {
|
|
161
|
+
console.error("[Lambda] Express error:", err);
|
|
162
|
+
resolve({
|
|
163
|
+
statusCode: 500,
|
|
164
|
+
headers: { "content-type": "application/json" },
|
|
165
|
+
body: JSON.stringify({ error: err.message }),
|
|
166
|
+
isBase64Encoded: false,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
173
|
+
console.error("[Lambda] Handler error:", error);
|
|
174
|
+
resolve({
|
|
175
|
+
statusCode: 500,
|
|
176
|
+
headers: { "content-type": "application/json" },
|
|
177
|
+
body: JSON.stringify({ error: errorMessage }),
|
|
178
|
+
isBase64Encoded: false,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Cloudflare Workers Adapter for ExpressoTS Micro API
|
|
4
|
+
*
|
|
5
|
+
* Converts Cloudflare Workers requests to Express format.
|
|
6
|
+
* Note: This adapter requires a Cloudflare Workers-compatible Express implementation
|
|
7
|
+
* or uses a fetch-based approach.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.cloudflareAdapter = cloudflareAdapter;
|
|
11
|
+
/**
|
|
12
|
+
* Create a Cloudflare Workers handler from an Express app
|
|
13
|
+
*
|
|
14
|
+
* Note: Full Express compatibility in Cloudflare Workers requires
|
|
15
|
+
* additional setup. This adapter provides a basic implementation.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // src/worker.ts
|
|
20
|
+
* import { createMicroAPI, cloudflareAdapter } from "@expressots/adapter-express";
|
|
21
|
+
*
|
|
22
|
+
* const microAPI = createMicroAPI();
|
|
23
|
+
* const app = microAPI.build();
|
|
24
|
+
*
|
|
25
|
+
* app.Middleware.parse();
|
|
26
|
+
* app.Route.get("/", (req, res) => res.json({ message: "Hello Workers!" }));
|
|
27
|
+
*
|
|
28
|
+
* export default cloudflareAdapter(app);
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* wrangler.toml:
|
|
32
|
+
* ```toml
|
|
33
|
+
* name = "my-worker"
|
|
34
|
+
* main = "src/worker.ts"
|
|
35
|
+
* compatibility_date = "2024-01-01"
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function cloudflareAdapter(app, config) {
|
|
39
|
+
const expressApp = "getExpressApp" in app && app.getExpressApp ? app.getExpressApp() : app;
|
|
40
|
+
const debug = config?.debug ?? false;
|
|
41
|
+
return {
|
|
42
|
+
async fetch(request, env, ctx) {
|
|
43
|
+
const url = new URL(request.url);
|
|
44
|
+
if (debug) {
|
|
45
|
+
console.log("[Cloudflare] Request:", {
|
|
46
|
+
method: request.method,
|
|
47
|
+
url: request.url,
|
|
48
|
+
path: url.pathname,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// Parse body if present
|
|
52
|
+
let body;
|
|
53
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
54
|
+
body = await request.text();
|
|
55
|
+
}
|
|
56
|
+
// Build query parameters
|
|
57
|
+
const query = {};
|
|
58
|
+
url.searchParams.forEach((value, key) => {
|
|
59
|
+
query[key] = value;
|
|
60
|
+
});
|
|
61
|
+
// Build headers
|
|
62
|
+
const headers = {};
|
|
63
|
+
request.headers.forEach((value, key) => {
|
|
64
|
+
headers[key.toLowerCase()] = value;
|
|
65
|
+
});
|
|
66
|
+
return new Promise((resolve) => {
|
|
67
|
+
// Create mock Express-compatible request object
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
const req = {
|
|
70
|
+
method: request.method,
|
|
71
|
+
url: url.pathname + url.search,
|
|
72
|
+
path: url.pathname,
|
|
73
|
+
headers,
|
|
74
|
+
query,
|
|
75
|
+
params: {},
|
|
76
|
+
body: body ? JSON.parse(body) : undefined,
|
|
77
|
+
get: (name) => headers[name.toLowerCase()],
|
|
78
|
+
cloudflare: { env, ctx },
|
|
79
|
+
};
|
|
80
|
+
// Create mock Express-compatible response object
|
|
81
|
+
const chunks = [];
|
|
82
|
+
const responseHeaders = {};
|
|
83
|
+
let statusCode = 200;
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
+
const res = {
|
|
86
|
+
statusCode: 200,
|
|
87
|
+
setHeader: (name, value) => {
|
|
88
|
+
responseHeaders[name.toLowerCase()] = value;
|
|
89
|
+
},
|
|
90
|
+
getHeader: (name) => responseHeaders[name.toLowerCase()],
|
|
91
|
+
write: (chunk) => {
|
|
92
|
+
chunks.push(Buffer.from(chunk));
|
|
93
|
+
},
|
|
94
|
+
end: (chunk) => {
|
|
95
|
+
if (chunk) {
|
|
96
|
+
chunks.push(Buffer.from(chunk));
|
|
97
|
+
}
|
|
98
|
+
const bodyBuffer = Buffer.concat(chunks);
|
|
99
|
+
if (debug) {
|
|
100
|
+
console.log("[Cloudflare] Response:", {
|
|
101
|
+
statusCode,
|
|
102
|
+
headers: responseHeaders,
|
|
103
|
+
bodyLength: bodyBuffer.length,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
resolve(new globalThis.Response(bodyBuffer, {
|
|
107
|
+
status: statusCode,
|
|
108
|
+
headers: responseHeaders,
|
|
109
|
+
}));
|
|
110
|
+
},
|
|
111
|
+
status: (code) => {
|
|
112
|
+
statusCode = code;
|
|
113
|
+
return res;
|
|
114
|
+
},
|
|
115
|
+
json: (data) => {
|
|
116
|
+
res.setHeader("content-type", "application/json");
|
|
117
|
+
res.end(JSON.stringify(data));
|
|
118
|
+
},
|
|
119
|
+
send: (data) => {
|
|
120
|
+
if (typeof data === "string") {
|
|
121
|
+
res.setHeader("content-type", "text/html");
|
|
122
|
+
res.end(data);
|
|
123
|
+
}
|
|
124
|
+
else if (Buffer.isBuffer(data)) {
|
|
125
|
+
res.end(data);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
res.json(data);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
// Handle request through Express
|
|
133
|
+
try {
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
135
|
+
expressApp(req, res, (err) => {
|
|
136
|
+
if (err) {
|
|
137
|
+
console.error("[Cloudflare] Express error:", err);
|
|
138
|
+
resolve(new globalThis.Response(JSON.stringify({ error: err.message }), {
|
|
139
|
+
status: 500,
|
|
140
|
+
headers: {
|
|
141
|
+
"content-type": "application/json",
|
|
142
|
+
},
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
149
|
+
console.error("[Cloudflare] Handler error:", error);
|
|
150
|
+
resolve(new globalThis.Response(JSON.stringify({ error: errorMessage }), {
|
|
151
|
+
status: 500,
|
|
152
|
+
headers: { "content-type": "application/json" },
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Serverless Adapters for ExpressoTS Micro Template
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cloudflareAdapter = exports.vercelAdapter = exports.awsLambdaAdapter = void 0;
|
|
7
|
+
var aws_lambda_adapter_js_1 = require("./aws-lambda.adapter.js");
|
|
8
|
+
Object.defineProperty(exports, "awsLambdaAdapter", { enumerable: true, get: function () { return aws_lambda_adapter_js_1.awsLambdaAdapter; } });
|
|
9
|
+
var vercel_adapter_js_1 = require("./vercel.adapter.js");
|
|
10
|
+
Object.defineProperty(exports, "vercelAdapter", { enumerable: true, get: function () { return vercel_adapter_js_1.vercelAdapter; } });
|
|
11
|
+
var cloudflare_adapter_js_1 = require("./cloudflare.adapter.js");
|
|
12
|
+
Object.defineProperty(exports, "cloudflareAdapter", { enumerable: true, get: function () { return cloudflare_adapter_js_1.cloudflareAdapter; } });
|