Skip to content

Commit

Permalink
fix: faas middle http (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
echosoar committed Jul 27, 2020
1 parent 9074d7c commit 27de83b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/faas-cli-plugin-package/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ export class PackagePlugin extends BasePlugin {
delete this.core.service.functions[functionName];
}
return {
...func,
path: httpEvent.http.path,
handler: func.handler,
};
})
.filter((func: any) => !!func);
Expand Down
6 changes: 4 additions & 2 deletions packages/faas/src/starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ export class FaaSStarter implements IFaaSStarter {
const context: FaaSContext = this.getContext(args.shift());

if (funOptions && funOptions.mod) {
// invoke middleware, just for http
let fnMiddlewere = [];
fnMiddlewere = fnMiddlewere.concat(this.globalMiddleware);
// invoke middleware, just for http
if (context.headers && context.get) {
fnMiddlewere = fnMiddlewere.concat(this.globalMiddleware);
}
fnMiddlewere = fnMiddlewere.concat(funOptions.middleware);
if (fnMiddlewere.length) {
const mw: any[] = await this.loadMiddleware(fnMiddlewere);
Expand Down
28 changes: 20 additions & 8 deletions packages/serverless-spec-builder/src/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ export function writeWrapper(options: {
const functions = service.functions || {};
for (const func in functions) {
const handlerConf = functions[func];

// for fp
if (handlerConf.isFunctional) {
if (!functionMap?.functionList) {
functionMap = { functionList: [] };
}
functionMap.functionList.push({
functionName: handlerConf.exportFunction,
functionHandler: handlerConf.handler,
functionFilePath: handlerConf.sourceFilePath,
functionMap = assignToFunctionMap(functionMap, handlerConf);
// for aggregation fp
if (handlerConf._handlers) {
handlerConf._handlers.forEach(innerHandlerConf => {
functionMap = assignToFunctionMap(functionMap, innerHandlerConf);
});
}

Expand Down Expand Up @@ -122,6 +120,20 @@ export function writeWrapper(options: {
}
}

const assignToFunctionMap = (functionMap, handlerConf) => {
if (handlerConf.isFunctional) {
if (!functionMap?.functionList) {
functionMap = { functionList: [] };
}
functionMap.functionList.push({
functionName: handlerConf.exportFunction,
functionHandler: handlerConf.handler,
functionFilePath: handlerConf.sourceFilePath,
});
}
return functionMap;
};

export function formetAggregationHandlers(handlers) {
if (!handlers || !handlers.length) {
return [];
Expand Down

0 comments on commit 27de83b

Please sign in to comment.