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

Commit

Permalink
feat: add middleware info from user config
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Apr 30, 2020
1 parent 788e417 commit 67b9adc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 0 additions & 1 deletion packages/faas/src/config.default.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export const middleware = [];
export const keys = '';
13 changes: 8 additions & 5 deletions packages/faas/src/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { Configuration, App, Config } from '@midwayjs/decorator';
import { ILifeCycle, IMidwayContainer } from '@midwayjs/core';
import { ILifeCycle } from '@midwayjs/core';

@Configuration({
importConfigs: ['./config.default'],
})
export class FaaSContainerConfiguration implements ILifeCycle {
@App()
app;
app: {
globalMiddleware: string[];
};

@Config('middleware')
middleware;
middleware: string[];

async onReady(container: IMidwayContainer) {
async onReady() {
// add middleware from user config
for (const mw of this.middleware) {
this.app.use(mw);
this.app.globalMiddleware.push(mw);
}
}
}

0 comments on commit 67b9adc

Please sign in to comment.