@midwayjs/faas 3.10.10 → 3.10.12

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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Context, IFaaSConfigurationOptions, Application, NextFunction, HandlerOptions, HttpResponseFormat } from './interface';
2
+ import { Context, IFaaSConfigurationOptions, Application, NextFunction, HandlerOptions, HttpResponseFormat, wrapHttpRequestOptions } from './interface';
3
3
  import { BaseFramework, CommonMiddlewareUnion, ContextMiddlewareManager, FunctionMiddleware, IMidwayBootstrapOptions, MidwayEnvironmentService, MidwayFrameworkType, MidwayMiddlewareService, RouterInfo } from '@midwayjs/core';
4
4
  import { LoggerOptions } from '@midwayjs/logger';
5
5
  import * as http from 'http';
@@ -36,7 +36,7 @@ export declare class MidwayFaaSFramework extends BaseFramework<Application, Cont
36
36
  formatHttpResponse(context: any, options?: {
37
37
  supportBufferResponse?: boolean;
38
38
  }): HttpResponseFormat;
39
- wrapHttpRequest(req: http.IncomingMessage | Record<string, any>, res?: http.ServerResponse | Record<string, any>): Promise<unknown>;
39
+ wrapHttpRequest(req: http.IncomingMessage | Record<string, any>, res?: http.ServerResponse | Record<string, any>, options?: wrapHttpRequestOptions): Promise<unknown>;
40
40
  /**
41
41
  * @deprecated
42
42
  * @param middlewareId
package/dist/framework.js CHANGED
@@ -191,7 +191,7 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
191
191
  };
192
192
  }
193
193
  async invokeTriggerFunction(context, handlerMapping, options) {
194
- var _a;
194
+ var _a, _b;
195
195
  let funOptions = this.funMappingStore.get(handlerMapping);
196
196
  const isHttpFunction = options.isHttpFunction;
197
197
  if (!funOptions && isHttpFunction) {
@@ -200,12 +200,24 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
200
200
  const matchRes = core_1.PathToRegexpUtil.match(funOptions.fullUrlFlattenString)(context.path);
201
201
  context.req.pathParameters = matchRes['params'] || {};
202
202
  }
203
+ else {
204
+ // options request pass throuth to middleware
205
+ if (((_a = context.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'options') {
206
+ funOptions = {
207
+ url: context.path,
208
+ method: 'options',
209
+ requestMethod: 'options',
210
+ controllerMiddleware: [],
211
+ middleware: [],
212
+ };
213
+ }
214
+ }
203
215
  }
204
216
  if (!funOptions) {
205
217
  throw new Error(`function handler = ${handlerMapping} not found`);
206
218
  }
207
219
  context = this.getContext(context);
208
- if ((_a = this.configurationOptions.applicationAdapter) === null || _a === void 0 ? void 0 : _a.runContextHook) {
220
+ if ((_b = this.configurationOptions.applicationAdapter) === null || _b === void 0 ? void 0 : _b.runContextHook) {
209
221
  this.configurationOptions.applicationAdapter.runContextHook(context);
210
222
  }
211
223
  const result = await (await this.applyMiddleware(async (ctx, next) => {
@@ -312,9 +324,9 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
312
324
  body: context.body,
313
325
  };
314
326
  }
315
- async wrapHttpRequest(req, res) {
327
+ async wrapHttpRequest(req, res, options) {
316
328
  const newReq = res ? new serverless_http_parser_1.HTTPRequest(req, res) : req;
317
- const newRes = new serverless_http_parser_1.HTTPResponse();
329
+ const newRes = new serverless_http_parser_1.HTTPResponse(options);
318
330
  return this.createHttpContext(newReq, newRes);
319
331
  }
320
332
  /**
@@ -1,7 +1,7 @@
1
1
  import { MidwayRequestContainer, IMidwayApplication, IConfigurationOptions, IMidwayContext, NextFunction as BaseNextFunction, CommonMiddlewareUnion, ContextMiddlewareManager, IMidwayBootstrapOptions, ObjectIdentifier } from '@midwayjs/core';
2
2
  import { FaaSHTTPContext } from '@midwayjs/faas-typings';
3
3
  import { ILogger } from '@midwayjs/logger';
4
- import { Application as ServerlessHttpApplication } from '@midwayjs/serverless-http-parser';
4
+ import { Application as ServerlessHttpApplication, HttpResponseOptions } from '@midwayjs/serverless-http-parser';
5
5
  export interface FaaSContext extends IMidwayContext<FaaSHTTPContext> {
6
6
  logger: ILogger;
7
7
  env: string;
@@ -90,4 +90,6 @@ export interface HttpResponseFormat<T = unknown> {
90
90
  headers: Record<string, string>;
91
91
  body: T;
92
92
  }
93
+ export interface wrapHttpRequestOptions extends HttpResponseOptions {
94
+ }
93
95
  //# sourceMappingURL=interface.d.ts.map
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@midwayjs/faas",
3
- "version": "3.10.10",
3
+ "version": "3.10.12",
4
4
  "main": "dist/index",
5
5
  "typings": "index.d.ts",
6
6
  "dependencies": {
7
7
  "@midwayjs/core": "^3.10.10",
8
- "@midwayjs/faas-typings": "^3.6.0",
8
+ "@midwayjs/faas-typings": "^3.10.11",
9
9
  "@midwayjs/logger": "^2.15.0",
10
- "@midwayjs/serverless-http-parser": "^3.10.0",
10
+ "@midwayjs/serverless-http-parser": "^3.10.11",
11
11
  "@midwayjs/simple-lock": "^1.1.4"
12
12
  },
13
13
  "devDependencies": {
14
- "@midwayjs/mock": "^3.10.10",
15
- "@midwayjs/serverless-fc-starter": "^3.10.10",
16
- "@midwayjs/serverless-scf-starter": "^3.10.0",
14
+ "@midwayjs/mock": "^3.10.11",
15
+ "@midwayjs/serverless-fc-starter": "^3.10.11",
16
+ "@midwayjs/serverless-scf-starter": "^3.10.11",
17
17
  "mm": "3.2.1"
18
18
  },
19
19
  "engines": {
@@ -45,5 +45,5 @@
45
45
  "url": "git@github.com:midwayjs/midway.git"
46
46
  },
47
47
  "license": "MIT",
48
- "gitHead": "93d333e82e75b6eb44ab83f74a378172508730d6"
48
+ "gitHead": "5fbc455a226942afc49bf414fcdbd2ef88d3db96"
49
49
  }