Skip to content

Commit 08d2ced

Browse files
authored
Merge branch 'master' into ts
2 parents 44aecb3 + 5e6ea50 commit 08d2ced

46 files changed

Lines changed: 1555 additions & 156 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.autod.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = {
2525
'@types/accepts',
2626
'@types/koa',
2727
'@types/koa-router',
28+
'@types/urllib',
2829
],
2930
test: 'scripts',
3031
};

History.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,89 @@
11
# History
22

3+
## 2018-05-03, Version 2.8.0 @dead-horse
4+
5+
### Notable changes
6+
7+
* **feature**
8+
* add time duration for dump config
9+
10+
* **fix**
11+
* make singleton work for unextensible or frozen instance
12+
13+
* **docs**
14+
* switch to English document
15+
* add middleware to Application and other ts improvement (typescript)
16+
* update wxapp-socket-io project to weapp.socket.io
17+
* update title and remove unused files
18+
19+
### Commits
20+
21+
* [[`4b602d037`](http://github.com/eggjs/egg/commit/4b602d037554b72c8261b7abb7efd94f8f59f3fe)] - fix: make singleton work for unextensible or frozen instance (#2472) (Yiyu He <<dead_horse@qq.com>>)
22+
* [[`824200c11`](http://github.com/eggjs/egg/commit/824200c11cac8e20b2c275daa7f5a4a365c71259)] - feat: add time duration for dump config (#2485) (Haoliang Gao <<sakura9515@gmail.com>>)
23+
* [[`73dac083d`](http://github.com/eggjs/egg/commit/73dac083d2a029f893e9b6737080c921027e308f)] - docs: update wxapp-socket-io project to weapp.socket.io (#2421) (liuguili <<gongzili456@gmail.com>>)
24+
* [[`1ada8e384`](http://github.com/eggjs/egg/commit/1ada8e3848be9f09680d7cac091fb14206df5a11)] - feat(d.ts): add middleware to Application and other ts improvement (#2465) (Axes <<whxaxes@qq.com>>)
25+
* [[`437785315`](http://github.com/eggjs/egg/commit/437785315f28a828ea0cf7bece80223d5b796dc5)] - docs: fix the code error of LOCALS in view.md (#2464) (zjz19901029 <<346663801@qq.com>>)
26+
* [[`f341b9fb8`](http://github.com/eggjs/egg/commit/f341b9fb8bdf36b6280500578e8448c59aec10f1)] - chore: update title and remove unused files (#2433) (TZ |
27+
天猪 <<atian25@qq.com>>)
28+
* [[`a5ab29cbd`](http://github.com/eggjs/egg/commit/a5ab29cbd1de0f5425019085258a496b4bce8b45)] - docs: switch to English document (#2426) (Haoliang Gao <<sakura9515@gmail.com>>)
29+
* [[`4ab7df25f`](http://github.com/eggjs/egg/commit/4ab7df25f152609d494745eac2794b78e66444f0)] - deps: update dependencies, add @types/urllib to autod config (#2423) (Yiyu He <<dead_horse@qq.com>>)
30+
31+
## 2018-04-17, Version 2.7.1 @dead-horse
32+
33+
### Notable changes
34+
35+
* **fix**
36+
* imporve compatibility of singleton
37+
38+
### Commits
39+
40+
* [[`e4d219f`](http://github.com/eggjs/egg/commit/e4d219f1aaecbca13601c7813e57c67934e8c32b)] - fix: imporve compatibility of singleton (#2410) (Yiyu He <<dead_horse@qq.com>>)
41+
42+
## 2018-04-16, Version 2.7.0 @dead-horse [DEPRECATED]
43+
44+
### Notable changes
45+
46+
* **feature**
47+
* singleton support asynchronous create function
48+
49+
* **fix**
50+
* dump config support circular json
51+
52+
* **docs**
53+
* improve router and typescript
54+
55+
### Commits
56+
57+
* [[`3d499a9`](http://github.com/eggjs/egg/commit/3d499a90bab7095569e115e223de40e63812f2f5)] - docs(plugin): add singleton support async create function (#2392) (Yiyu He <<dead_horse@qq.com>>)
58+
* [[`05d925f`](http://github.com/eggjs/egg/commit/05d925fea4e0b2d8efa48cb01ced2133c0c059cd)] - docs: change English document on Readme (#2397) (Haoliang Gao <<sakura9515@gmail.com>>)
59+
* [[`590bd8c`](http://github.com/eggjs/egg/commit/590bd8cb400845706ec7cc84232b812cb468c8ac)] - fix: dumpConfig support circular json (#2394) (Yiyu He <<dead_horse@qq.com>>)
60+
* [[`3a489b6`](http://github.com/eggjs/egg/commit/3a489b6f47b39ff2ec31efe936504918300b3f08)] - feat(singleton): support async create function (#2382) (Yiyu He <<dead_horse@qq.com>>)
61+
* [[`a5b6731`](http://github.com/eggjs/egg/commit/a5b673133b35e9b005e19c1e3267a2ff3d58e32b)] - docs: chore for router and typescript (#2390) (TZ | 天猪 <<atian25@qq.com>>)
62+
* [[`ee2d2b3`](http://github.com/eggjs/egg/commit/ee2d2b3c33671a822b45a6c474d3710aab5e70d5)] - docs(passport): translation for passport tutorial (#2235) (Cemre Mengu <<cemremengu@gmail.com>>)
63+
* [[`6fad4e1`](http://github.com/eggjs/egg/commit/6fad4e1bed3c388e964fc656244e5e606b258085)] - chore: update package.json for release (#2381) (TZ | 天猪 <<atian25@qq.com>>)
64+
65+
## 2018-04-12, Version 2.6.1 @atian25
66+
67+
### Notable changes
68+
69+
* **docs**
70+
* TypeScript Guide (#2324)
71+
* fix d.ts with ts support
72+
* docs improve
73+
74+
### Commits
75+
76+
* [[`2998bf733`](http://github.com/eggjs/egg/commit/2998bf733268d4d88d5fc77e05943b3fa0f824d4)] - chore(typings): add index signature of EggAppConfig (#2359) (waiting <<waiting@xiaozhong.biz>>)
77+
* [[`5f2358bbd`](http://github.com/eggjs/egg/commit/5f2358bbdd6e21a1ab387a8425d0fefc30954227)] - docs: intro session.renew in the doc (#2375) (Yiyu He <<dead_horse@qq.com>>)
78+
* [[`f0e7773f2`](http://github.com/eggjs/egg/commit/f0e7773f28eb7a233230a847ff2f8bc737aa3c01)] - docs: add TypeScript Guide (#2324) (TZ | 天猪 <<atian25@qq.com>>)
79+
* [[`cd418f57a`](http://github.com/eggjs/egg/commit/cd418f57a843b504dcac6d8c25b99026e1edf072)] - docs(controller): add ctx.redirect (#2373) (Yiyu He <<dead_horse@qq.com>>)
80+
* [[`2fafb16b8`](http://github.com/eggjs/egg/commit/2fafb16b8810e41b86d15f51257c2a0531c78357)] - docs(socketio): update demo & solve problem on chrome (#2354) (Suyi <<thonatos@users.noreply.github.com>>)
81+
* [[`ba708ca4e`](http://github.com/eggjs/egg/commit/ba708ca4e911a345d2ee6aea5d4cf5845f93212b)] - feat: support customized client error (#2283) (Khaidi Chu <<i@2333.moe>>)
82+
* [[`8697140d6`](http://github.com/eggjs/egg/commit/8697140d6ab10f42980ea301e7122331b6e5573a)] - chore: add export to declarations (#2344) (Axes <<whxaxes@qq.com>>)
83+
* [[`441884145`](http://github.com/eggjs/egg/commit/4418841452a20a4fcca212e17dad0fbe9ff97646)] - chore(typings): export PowerPartial (#2327) (waiting <<waiting@xiaozhong.biz>>)
84+
* [[`33d39519e`](http://github.com/eggjs/egg/commit/33d39519e1bd9bb1451776abe4986cdf4dee7626)] - docs(passport): config passport-github behind of proxy (#2318) (Suyi <<thonatos@users.noreply.github.com>>)
85+
* [[`84e0dc4e7`](http://github.com/eggjs/egg/commit/84e0dc4e74e4e907d39b5485e1b19c3900aec393)] - fix(d.ts): add modifier to plugin and add middleware to config (#2322) (Axes <<whxaxes@qq.com>>)
86+
387
## 2018-04-04, Version 2.6.0 @atian25
488

589
### Notable changes

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,11 @@ Node.js >= 8.0.0 required.
4545

4646
## Docs & Community
4747

48-
- [Website && Documentations](https://eggjs.org)
48+
- [Website && Documentations](https://eggjs.org/en/index.html)
4949
- [Plugins](https://github.com/search?q=topic%3Aegg-plugin&type=Repositories)
5050
- [Frameworks](https://github.com/search?q=topic%3Aegg-framework&type=Repositories)
5151
- [Plugin Dependency](http://uml.mvnsearch.org/github/eggjs/egg/blob/master/docs/plugins.puml)
5252

53-
> All the documentations (comments, README, etc.) are in English, except the tutorials and api documentations are still [being translated](https://github.com/eggjs/egg/issues/363).
54-
> Feel free to join us and translate egg documentations. It's appreciated.
55-
5653
## Getting Started
5754

5855
Follow the commands listed below.

README.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $ npm install egg --save
3838
- ✔︎ 内置多进程管理
3939
- ✔︎ 高度可扩展的插件机制
4040
- ✔︎ 深度框架定制
41-
- ✔︎ 丰富的[插件](https://eggjs.org/badgeboard/)
41+
- ✔︎ 丰富的[插件](https://github.com/search?q=topic%3Aegg-plugin&type=Repositories)
4242

4343
## 文档和社区
4444

config/config.default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ module.exports = appInfo => {
318318
* @property {Number} responseTimeout - response timeout, default is 60000
319319
*/
320320
config.clusterClient = {
321+
maxWaitTime: 60000,
321322
responseTimeout: 60000,
322323
};
323324

docs/_config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ title: Egg.js
22
subtitle: "Born to build better enterprise frameworks and apps"
33
description: "Born to build better enterprise frameworks and apps"
44
language:
5-
- zh-cn
65
- en
6+
- zh-cn
77
timezone: UTC
88
url: https://eggjs.org
99
root: /
@@ -26,4 +26,4 @@ less:
2626

2727
deer:
2828
spmAPos: 'a454'
29-
spmBPos: 'b4893'
29+
spmBPos: 'b4893'

docs/source/_data/guide_toc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Tutorials:
3535
Passport: /tutorials/passport.html
3636
Socket.IO: /tutorials/socketio.html
3737
Assets: /tutorials/assets.html
38+
TypeScript: /tutorials/typescript.html
3839
Advanced:
3940
Loader: /advanced/loader.html
4041
Plugin Development: /advanced/plugin.html

docs/source/en/advanced/plugin.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Plugin is actually a 'mini application', directory of plugin is as below
5656
└── mw.test.js
5757
```
5858

59-
It is almost the same as the application directory, what's the difference?
59+
It is almost the same as the application directory, what's the difference?
6060

6161
1. Plugin have no independant router or controller. This is because:
6262

@@ -135,7 +135,7 @@ We've discussed what plugin is. Now what can it do?
135135

136136
### Built-in Objects API Extension
137137

138-
Extend the built-in objects of the framework, just like the application
138+
Extend the built-in objects of the framework, just like the application
139139

140140
- `app/extend/request.js` - extends Koa#Request object
141141
- `app/extend/response.js` - extends Koa#Response object
@@ -173,7 +173,7 @@ Extend the built-in objects of the framework, just like the application
173173
const assert = require('assert');
174174

175175
module.exports = app => {
176-
// insert static middleware before bodyParser
176+
// insert static middleware before bodyParser
177177
const index = app.config.coreMiddleware.indexOf('bodyParser');
178178
assert(index >= 0, 'bodyParser highly needed');
179179

@@ -273,7 +273,7 @@ If each plugin makes their own implementation, all sorts of configs and initia
273273

274274
#### Writing Plugin
275275

276-
We simplify the [egg-mysql] plugin and to see how to write such a plugin:
276+
We simplify the [egg-mysql] plugin and to see how to write such a plugin:
277277

278278
```js
279279
// egg-mysql/app.js
@@ -284,7 +284,7 @@ module.exports = app => {
284284
}
285285

286286
/**
287-
* @param {Object} config The config which already processed by the framework. If the application configured multiple MySQL instances, each config would be passed in and call multiple createMysql
287+
* @param {Object} config The config which already processed by the framework. If the application configured multiple MySQL instances, each config would be passed in and call multiple createMysql
288288
* @param {Application} app the current application
289289
* @return {Object} return the created MySQL instance
290290
*/
@@ -294,16 +294,33 @@ function createMysql(config, app) {
294294
const client = new Mysql(config);
295295

296296
// check before start the application
297-
app.beforeStart(async function startMysql() {
297+
app.beforeStart(async () => {
298298
const rows = await client.query('select now() as currentTime;');
299-
const index = count++;
300-
app.coreLogger.info(`[egg-mysql] instance[${index}] status OK, rds currentTime: ${rows[0].currentTime}`);
299+
app.coreLogger.info(`[egg-mysql] init instance success, rds currentTime: ${rows[0].currentTime}`);
301300
});
302301

303302
return client;
304303
}
305304
```
306305

306+
The initialization function also support `Async function`, convenient for some special plugins that need to be asynchronous to get some configuration files.
307+
308+
```js
309+
async function createMysql(config, app) {
310+
// get mysql configurations asynchronous
311+
const mysqlConfig = await app.configManager.getMysqlConfig(config.mysql);
312+
assert(mysqlConfig.host && mysqlConfig.port && mysqlConfig.user && mysqlConfig.database);
313+
// create instance
314+
const client = new Mysql(mysqlConfig);
315+
316+
// check before start the application
317+
const rows = await client.query('select now() as currentTime;');
318+
app.coreLogger.info(`[egg-mysql] init instance success, rds currentTime: ${rows[0].currentTime}`);
319+
320+
return client;
321+
}
322+
```
323+
307324
As you can see, all we need to do for this plugin is passing in the field that need to be mounted and the corresponding initialization function. Framework will be in charge of managing all the configs and the ways to access the instances.
308325

309326
#### Application Layer Usage Case
@@ -366,7 +383,7 @@ exports.mysql = {
366383
};
367384
```
368385

369-
2. Access the corresponding instance by `app.mysql.get('db1')`
386+
2. Access the corresponding instance by `app.mysql.get('db1')`
370387

371388
```js
372389
// app/controller/post.js
@@ -388,12 +405,12 @@ module.exports = app => {
388405
// get MySQL config from configuration center { host, post, password, ... }
389406
const mysqlConfig = await app.configCenter.fetch('mysql');
390407
// create MySQL instance dynamically
391-
app.database = app.mysql.createInstance(mysqlConfig);
408+
app.database = app.mysql.createInstanceAsync(mysqlConfig);
392409
});
393410
};
394411
```
395412

396-
Access the instance through `app.database`
413+
Access the instance through `app.database`
397414

398415
```js
399416
// app/controller/post.js
@@ -455,7 +472,7 @@ We are very welcome your contribution to the new plugins, but also hope you foll
455472

456473
Egg defines the plugin name through the `eggPlugin.name`, it is only unique in application or framework, that means **many npm packages might get the same plugin name**, why design in this way?
457474

458-
First, Egg plugin do not only support npm package, it also supports search plugins in local directory. In Chapter [progressive](../tutorials/progressive.md) we mentioned how to make progress by using these two configurations. Directory is more friendly to unit test. So, Egg can not ensure uniqueness through npm package name.
475+
First, Egg plugin do not only support npm package, it also supports search plugins in local directory. In Chapter [progressive](../tutorials/progressive.md) we mentioned how to make progress by using these two configurations. Directory is more friendly to unit test. So, Egg can not ensure uniqueness through npm package name.
459476

460477
What's more, Egg can use this feature to make Adapter. For example, the plugin defined in[Template Develop Spec](./view-plugin.md#PluginNameSpecification) was named as view, but there are plugins named `egg-view-nunjucks` and `egg-view-react`, the users only need to change the plugin and modify the templates, no need to modify the Controller, because all these plugins have implemented the same API.
461478

docs/source/en/basics/controller.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,3 +920,22 @@ class ProxyController extends Controller {
920920
}
921921
}
922922
```
923+
924+
### Redirect
925+
926+
The framework overwrites koa's native `ctx.redirect` implementation with a security plugin to provide a more secure redirect.
927+
928+
929+
* `ctx.redirect(url)` Forbids redirect if it is not in the configured whitelist domain name.
930+
* `ctx.unsafeRedirect(url)` does not determine the domain name and redirect directly. Generally, it is not recommended to use it. Use it after clearly understanding the possible risks.
931+
932+
If you use the `ctx.redirect` method, you need to configure the application configuration file as follows:
933+
934+
```js
935+
// config/config.default.js
936+
exports.security = {
937+
domainWhiteList:['.domain.com'], // Security whitelist, starts with `.`
938+
};
939+
```
940+
941+
If the user does not configure the `domainWhiteList` or the `domainWhiteList` array to be empty, then all redirect requests will be released by default, which is equivalent to `ctx.unsafeRedirect(url)`.

docs/source/en/basics/router.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,5 @@ module.exports = app => {
341341
app.router.get('/admin/log', app.controller.admin.log);
342342
};
343343
```
344+
345+
or using [egg-router-plus](https://github.com/eggjs/egg-router-plus).

0 commit comments

Comments
 (0)