eggjs user-agent extend plugin
$ npm i @zqun/egg-useragent --save
Change ${app_root}/config/plugin.ts
to enable useragent plugin:
export = {
useragent: {
enable: true,
package: 'egg-useragent',
}
}
Configure useragent information in ${app_root}/config/config.default.ts
:
Instructions
config.useragent = {
app: true
}
Configure useragent information in ${app_root}/app/controller/home.ts
:
Controller
export class HomeController {
@get('/index')
public async index(ctx?): Promise<any> {
const { ctx, service } = this;
// 获取请求user-agent
const getAgent = ctx.getAgent();
console.log('--userAgent-->', getAgent);
//...
//业务逻辑
//...
// 正常返回
return {
message: '正常数据返回',
data: [
{
name: 'lee',
}
]
}
}
}
Please open an issue here.