Skip to content

Commit

Permalink
feat(boilerplate): update midway-ts-strict
Browse files Browse the repository at this point in the history
- split modal to config/config.modal.ts
- add ApiMiddleware demo used by HomeController
- ApiMiddleware use new exported type Middleware according to midwayjs#269
  • Loading branch information
waitingsong committed Jul 9, 2019
1 parent a016e9b commit c8388f0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export class HomeController {
@config() private readonly welcomeMsg: string,
) {}

@get('/')
@get('/', { middleware: ['apiMiddleware'] })
public index(ctx: Context): void {
ctx.body = this.welcomeMsg
ctx.body = `${ this.welcomeMsg } - ${ ctx.api.reqTimeStr }`
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { EggAppConfig, EggAppInfo, PowerPartial } from 'midway'
import { EggAppInfo } from 'midway'

import { DefaultConfig } from './config.modal'

export type DefaultConfig = PowerPartial<EggAppConfig>

export default (appInfo: EggAppInfo) => {
const config: DefaultConfig = {}
const config = <DefaultConfig> {}

// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_{{keys}}';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { EggAppConfig, PowerPartial } from 'midway'


export interface DefaultConfig extends PowerPartial<EggAppConfig> {
welcomeMsg: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { WebMiddleware, Middleware, provide } from 'midway'


@provide()
export class ApiMiddleware implements WebMiddleware {

public resolve(): Middleware {
return async (ctx, next) => {
ctx.api = {
reqTimeStr: new Date().toLocaleString(),
}
await next()
}
}

}

0 comments on commit c8388f0

Please sign in to comment.