diff --git a/docs/source/en/basics/app-start.md b/docs/source/en/basics/app-start.md index a93c859738..ccc6748ec0 100644 --- a/docs/source/en/basics/app-start.md +++ b/docs/source/en/basics/app-start.md @@ -9,9 +9,9 @@ For example, we need to load a list of national cities from the remote server du ```js // app.js module.exports = app => { - app.beforeStart(function* () { + app.beforeStart(async () => { // The lifecycle method runs before the application bootstraps - app.cities = yield app.curl('http://example.com/city.json', { + app.cities = await app.curl('http://example.com/city.json', { method: 'GET', dataType: 'json', }); @@ -22,9 +22,11 @@ module.exports = app => { `cities` attribute has attached on the global `app`. It can be accessed in the controller, ```js -// app/controller/city.js -module.exports = function* (ctx) { - // ctx.app.cities // access `cities` property on the global `ctx.app` +// app/controller/home.js +class HomeController extends Controller { + async index() { + // now you can use `ctx.app.cities` + } } ``` diff --git a/docs/source/zh-cn/basics/app-start.md b/docs/source/zh-cn/basics/app-start.md index c760afb3f7..9d508108b2 100644 --- a/docs/source/zh-cn/basics/app-start.md +++ b/docs/source/zh-cn/basics/app-start.md @@ -8,9 +8,9 @@ title: 启动自定义 ```js // app.js module.exports = app => { - app.beforeStart(function* () { + app.beforeStart(async () => { // 应用会等待这个函数执行完成才启动 - app.cities = yield app.curl('http://example.com/city.json', { + app.cities = await app.curl('http://example.com/city.json', { method: 'GET', dataType: 'json', }); @@ -21,9 +21,11 @@ module.exports = app => { 在 Controller 中就可以使用了: ```js -// app/controller/city.js -module.exports = function* (ctx) { - // ctx.app.cities 在上面启动期间已经加载,可以直接使用 +// app/controller/home.js +class HomeController extends Controller { + async index() { + // ctx.app.cities 在上面启动期间已经加载,可以直接使用 + } } ```