@yopdev/dev-server 1.1.6 → 1.2.0-alpha.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.
@@ -3,5 +3,11 @@ import { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";
3
3
  import { Service, Callback } from "./services";
4
4
  export declare const newLambdaHttpProxy: (name: string, config: {
5
5
  settings: HttpSettings;
6
- handler: (event: APIGatewayProxyEvent) => Promise<APIGatewayProxyResult>;
6
+ routes: Route[];
7
7
  }, callback?: Callback<string>) => Service<string>;
8
+ type Route = {
9
+ method: string;
10
+ path: RegExp;
11
+ handler: (event: APIGatewayProxyEvent) => Promise<APIGatewayProxyResult>;
12
+ };
13
+ export {};
@@ -6,12 +6,13 @@ var http_server_1 = require("./http-server");
6
6
  var mappers_1 = require("./mappers");
7
7
  var responses_1 = require("./responses");
8
8
  var services_1 = require("./services");
9
- var newLambdaHttpProxy = function (name, config, callback) { return new services_1.Service(new LambdaHttpProxy(name, config.settings, config.handler), callback); };
9
+ var newLambdaHttpProxy = function (name, config, callback) { return new services_1.Service(new LambdaHttpProxy(name, config.settings, config.routes), callback); };
10
10
  exports.newLambdaHttpProxy = newLambdaHttpProxy;
11
11
  var LambdaHttpProxy = /** @class */ (function () {
12
- function LambdaHttpProxy(name, settings, handler) {
12
+ function LambdaHttpProxy(name, settings, routes) {
13
13
  var _this = this;
14
14
  this.name = name;
15
+ this.routes = routes;
15
16
  this.start = function () { return _this.server.start(); };
16
17
  this.stop = function () { return _this.server.stop()
17
18
  .then(function () { return _this.LOGGER.info('stopped'); }); };
@@ -28,7 +29,13 @@ var LambdaHttpProxy = /** @class */ (function () {
28
29
  });
29
30
  };
30
31
  };
31
- this.server = new http_server_1.HttpServer(name, settings, this.handler(handler));
32
+ this.resolveRoute = function (request, body, response) {
33
+ return _this.routes.filter(function (r) { return r.method === request.method; })
34
+ .filter(function (r) { return request.url.match(r.path); })
35
+ .sort(function (r1, r2) { return r2.path.source.length - r1.path.source.length; })
36
+ .map(function (r) { return _this.handler(r.handler); })[0](request, body, response);
37
+ };
38
+ this.server = new http_server_1.HttpServer(name, settings, this.resolveRoute);
32
39
  this.LOGGER = logging_1.LoggerFactory.create("HTTP->LAMBDA[".concat(this.name, "]"));
33
40
  }
34
41
  return LambdaHttpProxy;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yopdev/dev-server",
3
- "version": "1.1.6",
3
+ "version": "1.2.0-alpha.0",
4
4
  "scripts": {
5
5
  "compile": "tsc",
6
6
  "test": "jest",
@@ -9,10 +9,11 @@
9
9
  "distclean": "rm -rf node_modules"
10
10
  },
11
11
  "devDependencies": {
12
- "ts-jest": "^29.1.1",
13
- "typescript": "^5.2.2",
14
12
  "@types/aws-lambda": "8.10.114",
15
- "@types/node": "^20.9.0"
13
+ "@types/node": "^20.9.0",
14
+ "axios": "^1.6.2",
15
+ "ts-jest": "^29.1.1",
16
+ "typescript": "^5.2.2"
16
17
  },
17
18
  "dependencies": {
18
19
  "@aws-sdk/client-dynamodb": "^3.451.0",