Skip to content

Commit

Permalink
docs: add more description at quickstart (#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored and fengmk2 committed Jun 13, 2017
1 parent ef7c864 commit 78a13d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
14 changes: 11 additions & 3 deletions docs/source/en/intro/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ exports.nunjucks = {
// config/config.default.js
module.exports = appInfo => {
const config = {};
config.keys = appInfo.name + '...';
config.keys = <YOUR_SECURITY_COOKE_KEYS>;

// add config
config.view = {
defaultViewEngine: 'nunjucks',
mapping: {
'.tpl': 'nunjucks',
'.tpl': 'nunjucks',
},
}
return config;
Expand Down Expand Up @@ -263,7 +263,7 @@ module.exports = app => {
// read config
const { serverUrl, pageSize } = this.app.config.news;

// use build-in HttpClient to GET hacker-news api
// use built-in HttpClient to GET hacker-news api
const { data: idList } = yield this.ctx.curl(`${serverUrl}/topstories.json`, {
data: {
orderBy: '"$key"',
Expand Down Expand Up @@ -314,6 +314,9 @@ exports.news = {
};
```

**Note: `async function` is also built-in supported, see [async-function](../tutorials/async-function.md).**


### Add Extensions

We might encounter a small problem here.
Expand Down Expand Up @@ -378,6 +381,9 @@ exports.robot = {

Now try it using `curl localhost:7001/news -A "Baiduspider"`.

**Note:both Koa1 and Koa2 style middleware is supported, see [Use Koa's Middleware](../basics/middleware.md#Use-Koa's-Middleware)**


### Add Configurations

When writing business logic,
Expand Down Expand Up @@ -420,6 +426,8 @@ module.exports = app => {

Unit Testing is very important, and Egg also provide [egg-bin] to help you write tests painless.

All the test files should place at `{app_root}/test/**/*.test.js`.

```js
// test/app/middleware/robot.test.js
const assert = require('assert');
Expand Down
14 changes: 11 additions & 3 deletions docs/source/zh-cn/intro/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ title: 快速入门

## 快速初始化

通过脚手架快速生成项目:
我们推荐直接使用脚手架,只需几条简单指令,即可快速生成项目:

```bash
$ npm i egg-init -g
Expand All @@ -32,6 +32,8 @@ $ open localhost:7001

但为了让大家更好的了解 Egg.js,接下来,我们将跳过脚手架,手动一步步的搭建出一个 [Hacker News](https://github.com/eggjs/examples/tree/master/hackernews)

**注意:实际项目中,我们推荐使用上一节的脚手架直接初始化。**

![Egg HackerNews Snapshoot](https://cloud.githubusercontent.com/assets/227713/22960991/812999bc-f37d-11e6-8bd5-a96ca37d0ff2.png)

### 初始化项目
Expand Down Expand Up @@ -162,13 +164,13 @@ exports.nunjucks = {
// config/config.default.js
module.exports = appInfo => {
const config = {};
config.keys = appInfo.name + '...';
config.keys = <此处改为你自己的 Cookie 安全字符串>;

// 添加配置
config.view = {
defaultViewEngine: 'nunjucks',
mapping: {
'.tpl': 'nunjucks',
'.tpl': 'nunjucks',
},
}
return config;
Expand Down Expand Up @@ -293,6 +295,8 @@ exports.news = {
};
```

**提示:框架本身也支持 `async function`,具体参见 [使用 async function 开发应用](../tutorials/async-function.md)**

### 编写扩展

遇到一个小问题,我们的资讯时间的数据是 UnixTime 格式的,我们希望显示为便于阅读的格式。
Expand Down Expand Up @@ -351,6 +355,8 @@ exports.robot = {

现在可以使用 `curl http://localhost:7001/news -A "Baiduspider"` 看看效果。

**提示:框架同时兼容 Koa1 和 Koa2 形式的中间件,具体参见 [使用 Koa 的中间件](../basics/middleware.md#使用-koa-的中间件)**

### 配置文件

写业务的时候,不可避免的需要有配置文件,框架提供了强大的配置合并管理功能:
Expand Down Expand Up @@ -391,6 +397,8 @@ module.exports = app => {

单元测试非常重要,框架也提供了 [egg-bin] 来帮开发者无痛的编写测试。

测试文件应该放在项目根目录下的 test 目录下,并以 `test.js` 为后缀名,即 `{app_root}/test/**/*.test.js`

```js
// test/app/middleware/robot.test.js
const assert = require('assert');
Expand Down
3 changes: 1 addition & 2 deletions docs/source/zh-cn/tutorials/async-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = app => {
}
```

**注意:在上面的 contorller 中,我们用 await 调用了 `service.post.create()` 方法,如果这个方法是 generator function 类型,则也需要改造成 async function 接口才可以被调用。**
**注意:在上面的 controller 中,我们用 await 调用了 `service.post.create()` 方法,如果这个方法是 generator function 类型,则也需要改造成 async function 接口才可以被调用。**

## 定时任务

Expand Down Expand Up @@ -73,7 +73,6 @@ module.exports = {

```js
// app/middleware/gzip.js

const isJSON = require('koa-is-json');
const zlib = require('zlib');

Expand Down

0 comments on commit 78a13d5

Please sign in to comment.