Skip to content
This repository has been archived by the owner on Jul 2, 2020. It is now read-only.

Commit

Permalink
fix: Fix inner mw (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed May 18, 2020
1 parent 6d5a3d9 commit aa91d29
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/faas/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class FaaSContainerConfiguration implements ILifeCycle {

async onReady() {
// add middleware from user config
if (this.app?.use) {
if (this.app?.use && this.middleware?.length) {
await this.app.useMiddleware(this.middleware);
}
}
Expand Down
10 changes: 3 additions & 7 deletions packages/faas/src/starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ export class FaaSStarter implements IFaaSStarter {

if (funOptions && funOptions.mod) {
// invoke middleware, just for http
const fnMiddlewere = [].concat(funOptions.middleware);
let fnMiddlewere = [];
fnMiddlewere = fnMiddlewere.concat(this.globalMiddleware);
fnMiddlewere = fnMiddlewere.concat(funOptions.middleware);
if (fnMiddlewere.length) {
const mw: any[] = await this.loadMiddleware(fnMiddlewere);
mw.push(async ctx => {
Expand Down Expand Up @@ -260,12 +262,6 @@ export class FaaSStarter implements IFaaSStarter {
await this.getApplicationContext().getAsync(module);
}

// load global web middleware
const globalMW = await this.loadMiddleware(this.globalMiddleware);
for (const mw of globalMW) {
this.webApplication.use(mw as any);
}

// now only for test case
if (typeof opts.cb === 'function') {
await opts.cb();
Expand Down

0 comments on commit aa91d29

Please sign in to comment.