mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
34 lines
661 B
TypeScript
34 lines
661 B
TypeScript
import { Controller, Service, Application } from 'egg';
|
|
|
|
// controller
|
|
class FooController extends Controller {
|
|
async getData() {
|
|
this.ctx.body = await this.service.foo.bar();
|
|
}
|
|
}
|
|
|
|
// add user controller and service
|
|
declare module 'egg' {
|
|
interface IController { // tslint:disable-line
|
|
foo: FooController;
|
|
}
|
|
interface IService { // tslint:disable-line
|
|
foo: FooService;
|
|
}
|
|
}
|
|
|
|
class FooService extends Service {
|
|
async bar() {
|
|
//
|
|
return this.config.env;
|
|
}
|
|
}
|
|
|
|
// router
|
|
|
|
function router(app: Application) {
|
|
const controller = app.controller;
|
|
app.get('/foo', controller.foo.getData);
|
|
app.post('/', controller.foo.getData);
|
|
}
|