注意 npm i midway-apollo 目前1.0.17 github源码版本较高,npm的还不能使用{ HotValue, GetValue }装饰器
@HotValue(‘className:三年二班’)
private className: string;
@GetValue(‘age’)
private age: string;
安装midway-apollo
配置 config.default.ts
可使用以下地址调试 login/pass apollo/admin
ui http://106.54.227.205/config.html?#/appid=midway-apollo
apollo:{
client: {
appId: 'midway-apollo',
accessKey: '36104c4b15784a7b97708435ef97ee27',
// configPath: './config/apolloConfig.json',
namespaceList: ['application'],
configServerUrl: 'http://106.54.227.205:8080',
},
}
配置configuration.ts
import * as apollo from 'midway-apollo'
@Configuration({
imports: [
...,
koa,
apollo,
...
],
importConfigs: [join(__dirname, './config')],
})
使用
import { Controller, Get } from '@midwayjs/decorator';
import { Apollo } from 'midway-apollo'
@Controller('/')
export class HomeController {
@Apollo('age')
private age: string;
@Get('/')
async home(): Promise<string> {
return 'Hello Midwayjs!'+'apollo.age='+this.age;
}
}