mirror of
https://github.com/eggjs/egg.git
synced 2024-12-04 07:14:30 +00:00
parent
c87a3f66c1
commit
53a9bf4f2f
@ -1,2 +1,4 @@
|
||||
test/fixtures
|
||||
test/benchmark
|
||||
examples/**/app/public
|
||||
logs
|
||||
run
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -12,3 +12,5 @@ run
|
||||
.tmp
|
||||
docs/CONTRIBUTING.md
|
||||
docs/README.md
|
||||
|
||||
!test/fixtures/apps/loader-plugin/node_modules
|
||||
|
||||
@ -8,4 +8,4 @@ install:
|
||||
script:
|
||||
- npm run ci
|
||||
after_script:
|
||||
- npm i codecov && codecov
|
||||
- npminstall codecov && codecov
|
||||
|
||||
@ -5,7 +5,7 @@ environment:
|
||||
|
||||
install:
|
||||
- ps: Install-Product node $env:nodejs_version
|
||||
- npm i npminstall && npminstall
|
||||
- npm i npminstall && node_modules\.bin\npminstall
|
||||
|
||||
test_script:
|
||||
- node --version
|
||||
|
||||
@ -2,19 +2,6 @@
|
||||
@startuml
|
||||
digraph world {
|
||||
"onerror";
|
||||
"userservice";
|
||||
"userrole";
|
||||
"session";
|
||||
"i18n";
|
||||
"validate";
|
||||
"watcher";
|
||||
"multipart";
|
||||
"security" -> "session";
|
||||
"development" -> "watcher";
|
||||
"rest";
|
||||
"static";
|
||||
"cors" -> "security";
|
||||
"logrotater";
|
||||
"schedule";
|
||||
}
|
||||
@enduml
|
||||
|
||||
47
examples/cookie/test/index.test.js
Normal file
47
examples/cookie/test/index.test.js
Normal file
@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const request = require('supertest-as-promised');
|
||||
const mm = require('egg-mock');
|
||||
|
||||
describe('example cookie test', () => {
|
||||
let app;
|
||||
|
||||
before(() => {
|
||||
const baseDir = path.dirname(__dirname);
|
||||
const customEgg = path.join(baseDir, '../..');
|
||||
app = mm.app({
|
||||
baseDir,
|
||||
customEgg,
|
||||
});
|
||||
return app.ready();
|
||||
});
|
||||
|
||||
after(() => app.close());
|
||||
|
||||
it('should GET / show "remember me" checkbox when cookie.remember not exists', () => {
|
||||
return request(app.callback())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect(/<input type="checkbox" name="remember"\/> remember me<\/label>/);
|
||||
});
|
||||
|
||||
it('should POST /remember to set cookie.remember = 1', () => {
|
||||
return request(app.callback())
|
||||
.post('/remember')
|
||||
.send({
|
||||
remember: 'true',
|
||||
})
|
||||
.expect(302)
|
||||
.expect('Location', '/')
|
||||
.expect('Set-Cookie', /^remember=1; path=\/; expires=[^;]+; httponly,remember\.sig=[^;]+; path=\/; expires=[^;]+; httponly$/);
|
||||
});
|
||||
|
||||
it('should GET /forget to delete cookie.remember', () => {
|
||||
return request(app.callback())
|
||||
.get('/forget')
|
||||
.expect(302)
|
||||
.expect('Location', '/')
|
||||
.expect('Set-Cookie', /^remember=; path=\/; expires=[^;]+; httponly$/);
|
||||
});
|
||||
});
|
||||
43
examples/cookie_session/test/index.test.js
Normal file
43
examples/cookie_session/test/index.test.js
Normal file
@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const request = require('supertest-as-promised');
|
||||
const mm = require('egg-mock');
|
||||
|
||||
describe('example cookie_session test', () => {
|
||||
let app;
|
||||
let cookie;
|
||||
|
||||
before(() => {
|
||||
const baseDir = path.dirname(__dirname);
|
||||
const customEgg = path.join(baseDir, '../..');
|
||||
app = mm.app({
|
||||
baseDir,
|
||||
customEgg,
|
||||
});
|
||||
return app.ready();
|
||||
});
|
||||
|
||||
after(() => app.close());
|
||||
|
||||
it('should GET / first time', () => {
|
||||
return request(app.callback())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect(/^1 times/)
|
||||
.expect('Set-Cookie', /^EGG_SESS=[^;]+; path=\/; expires=[^;]+; httponly$/)
|
||||
.expect(res => {
|
||||
cookie = res.headers['set-cookie'][0].split(';')[0];
|
||||
});
|
||||
});
|
||||
|
||||
it('should GET / second time', () => {
|
||||
return request(app.callback())
|
||||
.get('/')
|
||||
.set('Cookie', cookie)
|
||||
.expect(200)
|
||||
.expect(/^2 times/)
|
||||
// session.count change
|
||||
.expect('Set-Cookie', /^EGG_SESS=[^;]+; path=\/; expires=[^;]+; httponly$/);
|
||||
});
|
||||
});
|
||||
35
examples/helloworld/test/index.test.js
Normal file
35
examples/helloworld/test/index.test.js
Normal file
@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const request = require('supertest-as-promised');
|
||||
const mm = require('egg-mock');
|
||||
|
||||
describe('example helloworld test', () => {
|
||||
let app;
|
||||
|
||||
before(() => {
|
||||
const baseDir = path.dirname(__dirname);
|
||||
const customEgg = path.join(baseDir, '../..');
|
||||
app = mm.app({
|
||||
baseDir,
|
||||
customEgg,
|
||||
});
|
||||
return app.ready();
|
||||
});
|
||||
|
||||
after(() => app.close());
|
||||
|
||||
it('should GET / 200', () => {
|
||||
return request(app.callback())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Hello World');
|
||||
});
|
||||
|
||||
it('should GET /foo', () => {
|
||||
return request(app.callback())
|
||||
.get('/foo')
|
||||
.expect(200)
|
||||
.expect('Hello foo');
|
||||
});
|
||||
});
|
||||
3
examples/multipart/config/config.default.js
Normal file
3
examples/multipart/config/config.default.js
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
exports.keys = 'my keys';
|
||||
63
examples/multipart/test/index.test.js
Normal file
63
examples/multipart/test/index.test.js
Normal file
@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const request = require('supertest-as-promised');
|
||||
const mm = require('egg-mock');
|
||||
const formstream = require('formstream');
|
||||
const urllib = require('urllib');
|
||||
|
||||
describe.skip('example multipart test', () => {
|
||||
let app;
|
||||
let csrfToken;
|
||||
let cookies;
|
||||
let host;
|
||||
let server;
|
||||
|
||||
before(() => {
|
||||
const baseDir = path.dirname(__dirname);
|
||||
const customEgg = path.join(baseDir, '../..');
|
||||
app = mm.app({
|
||||
baseDir,
|
||||
customEgg,
|
||||
});
|
||||
server = app.listen();
|
||||
});
|
||||
|
||||
after(() => app.close());
|
||||
|
||||
it('should GET / show upload form', () => {
|
||||
return request(server)
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect(/<p>Image: <input type="file" name="image" \/><\/p>/)
|
||||
.expect(res => {
|
||||
console.log(res.headers, res.text);
|
||||
csrfToken = res.headers['x-csrf'];
|
||||
cookies = res.headers['set-cookie'].join(';');
|
||||
host = `http://127.0.0.1:${server.address().port}`;
|
||||
});
|
||||
});
|
||||
|
||||
it('should POST /upload success', done => {
|
||||
const form = formstream();
|
||||
form.file('file', __filename);
|
||||
// other form fields
|
||||
form.field('title', 'fengmk2 test title')
|
||||
.field('love', 'egg');
|
||||
|
||||
const headers = form.headers();
|
||||
headers.Cookie = cookies;
|
||||
urllib.request(`${host}/upload?_csrf=${csrfToken}`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
stream: form,
|
||||
dataType: 'json',
|
||||
}, (err, data, res) => {
|
||||
assert(!err, err && err.message);
|
||||
assert.equal(res.statusCode, 200);
|
||||
console.log(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
app.get('/', 'home');
|
||||
app.get('/', app.controller.home);
|
||||
};
|
||||
|
||||
3
examples/static/config/config.default.js
Normal file
3
examples/static/config/config.default.js
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
exports.keys = 'my keys';
|
||||
35
examples/static/test/index.test.js
Normal file
35
examples/static/test/index.test.js
Normal file
@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const request = require('supertest-as-promised');
|
||||
const mm = require('egg-mock');
|
||||
|
||||
describe('example static test', () => {
|
||||
let app;
|
||||
|
||||
before(() => {
|
||||
const baseDir = path.dirname(__dirname);
|
||||
const customEgg = path.join(baseDir, '../..');
|
||||
app = mm.app({
|
||||
baseDir,
|
||||
customEgg,
|
||||
});
|
||||
return app.ready();
|
||||
});
|
||||
|
||||
after(() => app.close());
|
||||
|
||||
it('should GET / 200', () => {
|
||||
return request(app.callback())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect(/<li>Download <a href="\/public\/hi\.txt">hi\.txt<\/a>\.<\/li>/);
|
||||
});
|
||||
|
||||
it('should GET /public/hi.txt', () => {
|
||||
return request(app.callback())
|
||||
.get('/public/hi.txt')
|
||||
.expect(200)
|
||||
.expect('hi egg.\n你好,蛋蛋。\n');
|
||||
});
|
||||
});
|
||||
@ -1,19 +1,19 @@
|
||||
/**
|
||||
* meta 中间件,放在最前面
|
||||
* meta middleware, should be the first middleware
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = function() {
|
||||
module.exports = () => {
|
||||
let serverId = process.env.HOSTNAME || '';
|
||||
if (serverId.indexOf('-') > 0) {
|
||||
// appname-90-1 => 90-1
|
||||
// appname-1-1 => 1-1
|
||||
serverId = serverId.split('-').slice(1).join('-');
|
||||
}
|
||||
|
||||
return function* (next) {
|
||||
return function* meta(next) {
|
||||
/**
|
||||
* 开始处理当前请求的时间戳,单位 `ms`,方便做一些时间计算。
|
||||
* Request start time
|
||||
* @member {Number} Context#starttime
|
||||
*/
|
||||
this.starttime = Date.now();
|
||||
@ -28,7 +28,7 @@ module.exports = function() {
|
||||
this.set('X-Server-Id', serverId);
|
||||
}
|
||||
|
||||
// 设置一个 x-readtime 头, 供 nginx access log 使用, 也方便调试
|
||||
// total response time header
|
||||
this.set('X-Readtime', Date.now() - this.starttime);
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(options) {
|
||||
module.exports = options => {
|
||||
return function* notfound(next) {
|
||||
yield next;
|
||||
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
const path = require('path');
|
||||
const MAX_AGE = 30 * 24 * 68 * 60;
|
||||
|
||||
module.exports = function fixture(options) {
|
||||
return function* (next) {
|
||||
module.exports = options => {
|
||||
return function* siteFile(next) {
|
||||
if (this.method !== 'HEAD' && this.method !== 'GET') return yield next;
|
||||
|
||||
if (!options.hasOwnProperty(this.path)) return yield next;
|
||||
|
||||
@ -27,13 +27,13 @@ module.exports = {
|
||||
/**
|
||||
* userrole
|
||||
* @member {Object} Plugin#userrole
|
||||
* @property {Boolean} enable - 默认 true
|
||||
* @property {Boolean} enable - `true` by default
|
||||
* @since 1.0.0
|
||||
*/
|
||||
// userrole: {
|
||||
// enable: true,
|
||||
// package: 'egg-userrole',
|
||||
// },
|
||||
userrole: {
|
||||
enable: true,
|
||||
package: 'egg-userrole',
|
||||
},
|
||||
|
||||
/**
|
||||
* session
|
||||
@ -63,10 +63,10 @@ module.exports = {
|
||||
* @property {Boolean} enable - 默认 true
|
||||
* @since 1.0.0
|
||||
*/
|
||||
// validate: {
|
||||
// enable: true,
|
||||
// package: 'egg-validate',
|
||||
// },
|
||||
validate: {
|
||||
enable: true,
|
||||
package: 'egg-validate',
|
||||
},
|
||||
|
||||
/**
|
||||
* file and dir watcher
|
||||
@ -87,7 +87,7 @@ module.exports = {
|
||||
*/
|
||||
// multipart: {
|
||||
// enable: true,
|
||||
// package: '@ali/egg-multipart',
|
||||
// package: 'egg-multipart',
|
||||
// },
|
||||
|
||||
/**
|
||||
@ -128,13 +128,13 @@ module.exports = {
|
||||
/**
|
||||
* `app/public` dir static serve
|
||||
* @member {Object} Plugin#static
|
||||
* @property {Boolean} enable - 默认 false
|
||||
* @property {Boolean} enable - `false` by default
|
||||
* @since 1.0.0
|
||||
*/
|
||||
// static: {
|
||||
// enable: false,
|
||||
// package: 'egg-static',
|
||||
// },
|
||||
static: {
|
||||
enable: false,
|
||||
package: 'egg-static',
|
||||
},
|
||||
|
||||
/**
|
||||
* CORS
|
||||
@ -142,10 +142,10 @@ module.exports = {
|
||||
* @property {Boolean} enable - 默认 false
|
||||
* @since 1.0.0
|
||||
*/
|
||||
// cors: {
|
||||
// enable: false,
|
||||
// package: 'egg-cors',
|
||||
// },
|
||||
cors: {
|
||||
enable: false,
|
||||
package: 'egg-cors',
|
||||
},
|
||||
|
||||
/**
|
||||
* logger file rotater
|
||||
|
||||
25
package.json
25
package.json
@ -3,18 +3,22 @@
|
||||
"version": "0.0.4",
|
||||
"description": "A web framework's framework for Node.js",
|
||||
"dependencies": {
|
||||
"egg-cluster": "*",
|
||||
"egg-loader": "*",
|
||||
"accepts": "^1.3.3",
|
||||
"agentkeepalive": "^2.1.1",
|
||||
"co": "^4.6.0",
|
||||
"debug": "^2.2.0",
|
||||
"delegates": "^1.0.0",
|
||||
"depd": "^1.1.0",
|
||||
"egg-cluster": "*",
|
||||
"egg-cookies": "^1.0.0",
|
||||
"egg-cors": "^0.0.2",
|
||||
"egg-loader": "*",
|
||||
"egg-logger": "^1.0.1",
|
||||
"egg-onerror": "~0.0.2",
|
||||
"egg-session": "~0.0.2",
|
||||
"egg-onerror": "*",
|
||||
"egg-session": "*",
|
||||
"egg-static": "*",
|
||||
"egg-userrole": "*",
|
||||
"egg-validate": "*",
|
||||
"graceful": "^1.0.0",
|
||||
"humanize-ms": "^1.2.0",
|
||||
"inflection": "^1.10.0",
|
||||
@ -39,7 +43,8 @@
|
||||
"co-sleep": "^0.0.1",
|
||||
"coffee": "^3.2.2",
|
||||
"egg-bin": "1",
|
||||
"egg-ci": "^1.0.0",
|
||||
"egg-ci": "1",
|
||||
"egg-mock": "*",
|
||||
"egg-plugin-puml": "1",
|
||||
"eslint": "^3.0.0",
|
||||
"eslint-config-egg": "^3.1.0",
|
||||
@ -48,7 +53,6 @@
|
||||
"glob": "^7.0.3",
|
||||
"merge-descriptors": "^1.0.1",
|
||||
"moment": "^2.13.0",
|
||||
"node-uuid": "^1.4.7",
|
||||
"once": "^1.3.3",
|
||||
"pedding": "^1.0.0",
|
||||
"rds": "^0.1.0",
|
||||
@ -56,9 +60,7 @@
|
||||
"should": "^6.0.3",
|
||||
"stream-wormhole": "^1.0.0",
|
||||
"supertest": "^1.2.0",
|
||||
"supertest-as-promised": "^3.2.0",
|
||||
"uuid": "^2.0.2",
|
||||
"uuid-js": "^0.7.5"
|
||||
"supertest-as-promised": "^3.2.0"
|
||||
},
|
||||
"main": "index.js",
|
||||
"files": [
|
||||
@ -67,11 +69,12 @@
|
||||
"index.js"
|
||||
],
|
||||
"scripts": {
|
||||
"lint": "eslint --fix lib test *.js",
|
||||
"lint": "eslint --fix lib test examples *.js",
|
||||
"test": "npm run lint && npm run test-local",
|
||||
"test-local": "egg-bin test",
|
||||
"test-examples": "TESTS=examples/**/test/**/*.test.js egg-bin test",
|
||||
"cov": "egg-bin cov",
|
||||
"ci": "node -v && npm run lint && npm run cov",
|
||||
"ci": "npm run lint && npm run test-examples && npm run cov",
|
||||
"autod": "autod",
|
||||
"doc": "./scripts/doc.sh",
|
||||
"puml": "puml . --dest ./docs",
|
||||
|
||||
54
test/benchmark/assign.js
Normal file
54
test/benchmark/assign.js
Normal file
@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
|
||||
const Benchmark = require('benchmark');
|
||||
const benchmarks = require('beautify-benchmark');
|
||||
const utils = require('../../lib/util');
|
||||
|
||||
new Benchmark.Suite()
|
||||
.add('Object.assign', () => {
|
||||
const a = {};
|
||||
const b = { a: 1, b: 2, c: 3, d: 4, e: 5 };
|
||||
Object.assign(a, b);
|
||||
})
|
||||
.add('for in', () => {
|
||||
const a = {};
|
||||
const b = { a: 1, b: 2, c: 3, d: 4, e: 5 };
|
||||
for (const key in b) {
|
||||
a[key] = b[key];
|
||||
}
|
||||
})
|
||||
.add('Object.keys', () => {
|
||||
const a = {};
|
||||
const b = { a: 1, b: 2, c: 3, d: 4, e: 5 };
|
||||
const keys = Object.keys(b);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const key = keys[i];
|
||||
a[key] = b[key];
|
||||
}
|
||||
})
|
||||
.add('utils.assign', () => {
|
||||
const a = {};
|
||||
const b = { a: 1, b: 2, c: 3, d: 4, e: 5 };
|
||||
utils.assign(a, b);
|
||||
})
|
||||
.on('cycle', event => {
|
||||
benchmarks.add(event.target);
|
||||
})
|
||||
.on('start', () => {
|
||||
console.log('\n node version: %s, date: %s\n Starting...',
|
||||
process.version, Date());
|
||||
})
|
||||
.on('complete', () => {
|
||||
benchmarks.log();
|
||||
process.exit(0);
|
||||
})
|
||||
.run({ async: false });
|
||||
|
||||
// node version: v4.2.3, date: Tue Jan 26 2016 16:52:46 GMT+0800 (CST)
|
||||
// Starting...
|
||||
// 4 tests completed.
|
||||
//
|
||||
// Object.assign x 646,034 ops/sec ±1.61% (86 runs sampled)
|
||||
// for in x 2,754,639 ops/sec ±1.21% (88 runs sampled)
|
||||
// Object.keys x 3,590,226 ops/sec ±1.04% (93 runs sampled)
|
||||
// utils.assign x 3,192,343 ops/sec ±0.69% (93 runs sampled)
|
||||
9
test/fixtures/apps/agent-app-sync/agent.js
vendored
Normal file
9
test/fixtures/apps/agent-app-sync/agent.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = agent => {
|
||||
agent.startAgent({
|
||||
name: 'test',
|
||||
client: { ready: cb => cb() },
|
||||
subscribe: (info, cb) => cb('test'),
|
||||
});
|
||||
};
|
||||
14
test/fixtures/apps/agent-app-sync/app.js
vendored
Normal file
14
test/fixtures/apps/agent-app-sync/app.js
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
const done = app.readyCallback();
|
||||
const test = app.createAppWorkerClient('test', {
|
||||
listen(cb) {
|
||||
this._subscribe('listening', cb);
|
||||
},
|
||||
});
|
||||
test.listen(arg => {
|
||||
app.arg = arg;
|
||||
done();
|
||||
})
|
||||
};
|
||||
7
test/fixtures/apps/agent-app-sync/app/router.js
vendored
Normal file
7
test/fixtures/apps/agent-app-sync/app/router.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
app.get('/', function*() {
|
||||
this.body = this.app.arg;
|
||||
})
|
||||
};
|
||||
3
test/fixtures/apps/agent-app-sync/package.json
vendored
Normal file
3
test/fixtures/apps/agent-app-sync/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "agent-app-sync"
|
||||
}
|
||||
11
test/fixtures/apps/agent-app/app.js
vendored
Normal file
11
test/fixtures/apps/agent-app/app.js
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
const done = app.readyCallback('foo');
|
||||
app.mockClient.subscribe({
|
||||
id: 'foo'
|
||||
}, value => {
|
||||
app.foo = value;
|
||||
done();
|
||||
});
|
||||
};
|
||||
25
test/fixtures/apps/agent-app/app/router.js
vendored
Normal file
25
test/fixtures/apps/agent-app/app/router.js
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
module.exports = app => {
|
||||
app.get('/', function*() {
|
||||
this.body = 'ok';
|
||||
});
|
||||
|
||||
app.get('/getData', function*() {
|
||||
this.body = yield app.mockClient.getData();
|
||||
});
|
||||
|
||||
app.get('/getError', function*() {
|
||||
try {
|
||||
yield app.mockClient.getError();
|
||||
} catch (err) {
|
||||
this.body = err.message;
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/getDataGenerator', function* () {
|
||||
this.body = yield app.mockClient.getDataGenerator();
|
||||
})
|
||||
|
||||
app.get('/sub', function*() {
|
||||
this.body = app.foo;
|
||||
});
|
||||
};
|
||||
10
test/fixtures/apps/agent-app/config/plugin.js
vendored
Normal file
10
test/fixtures/apps/agent-app/config/plugin.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
mock: {
|
||||
enable: true,
|
||||
path: path.join(__dirname, '../plugins/mock-client'),
|
||||
},
|
||||
};
|
||||
3
test/fixtures/apps/agent-app/package.json
vendored
Normal file
3
test/fixtures/apps/agent-app/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "agent-app"
|
||||
}
|
||||
29
test/fixtures/apps/agent-app/plugins/mock-client/agent.js
vendored
Normal file
29
test/fixtures/apps/agent-app/plugins/mock-client/agent.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const MockClient = require('./mock_client');
|
||||
|
||||
module.exports = agent => {
|
||||
const done = agent.readyCallback('agent_configclient');
|
||||
const options = agent.config.mock;
|
||||
|
||||
agent.mockClient = new MockClient();
|
||||
|
||||
// 启动 agent 任务
|
||||
agent.startAgent({
|
||||
client: agent.mockClient,
|
||||
name: 'mock',
|
||||
subscribe: function(info, listener) {
|
||||
agent.mockClient.on(info.id, listener);
|
||||
if (info.id === 'foo') {
|
||||
setTimeout(function() {
|
||||
agent.mockClient.emit('foo', 'bar');
|
||||
}, 100);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
agent.mockClient.ready(() => {
|
||||
agent.logger.info('[agent] %s started mockClient', agent.config.name);
|
||||
done();
|
||||
});
|
||||
};
|
||||
28
test/fixtures/apps/agent-app/plugins/mock-client/app.js
vendored
Normal file
28
test/fixtures/apps/agent-app/plugins/mock-client/app.js
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
const options = app.config.mock;
|
||||
|
||||
app.mockClient = app.createAppWorkerClient('mock', {
|
||||
subscribe: function(reg, listner) {
|
||||
this._subscribe(reg, listner);
|
||||
return this;
|
||||
},
|
||||
|
||||
* getData(id) {
|
||||
return yield this._invoke('getData', [id]);
|
||||
},
|
||||
|
||||
* getError() {
|
||||
return yield this._invoke('getError', []);
|
||||
},
|
||||
|
||||
* getDataGenerator(id) {
|
||||
return yield this._invoke('getDataGenerator', [id]);
|
||||
},
|
||||
}, options);
|
||||
|
||||
app.mockClient.ready(app.readyCallback('worker_mock_client'), {
|
||||
isWeakDep: app.config.runMode === 0,
|
||||
});
|
||||
};
|
||||
9
test/fixtures/apps/agent-app/plugins/mock-client/config/config.default.js
vendored
Normal file
9
test/fixtures/apps/agent-app/plugins/mock-client/config/config.default.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
return {
|
||||
mock: {
|
||||
name: 'mock',
|
||||
},
|
||||
};
|
||||
}
|
||||
65
test/fixtures/apps/agent-app/plugins/mock-client/mock_client.js
vendored
Normal file
65
test/fixtures/apps/agent-app/plugins/mock-client/mock_client.js
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
'use strict';
|
||||
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const sleep = require('co-sleep');
|
||||
|
||||
class MockClient extends EventEmitter {
|
||||
constructor(options) {
|
||||
super();
|
||||
|
||||
setImmediate(function() {
|
||||
this.ready(true);
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
ready(flagOrFunction) {
|
||||
this._ready = !!this._ready;
|
||||
this._readyCallbacks = this._readyCallbacks || [];
|
||||
|
||||
if (typeof flagOrFunction === 'function') {
|
||||
this._readyCallbacks.push(flagOrFunction);
|
||||
} else {
|
||||
this._ready = !!flagOrFunction;
|
||||
}
|
||||
|
||||
if (this._ready) {
|
||||
this._readyCallbacks.splice(0, Infinity).forEach(function(callback) {
|
||||
process.nextTick(callback);
|
||||
});
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
getCallback(id, callback) {
|
||||
setTimeout(function() {
|
||||
if (id === 'error') {
|
||||
callback(new Error('mock error'));
|
||||
} else {
|
||||
callback(null, 'mock data');
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
getData() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
setTimeout(function() {
|
||||
resolve('mock data');
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
|
||||
* getDataGenerator() {
|
||||
yield sleep(100);
|
||||
return 'mock data';
|
||||
}
|
||||
|
||||
getError() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
setTimeout(function() {
|
||||
reject(new Error('mock error'));
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MockClient;
|
||||
4
test/fixtures/apps/agent-die/agent.js
vendored
Normal file
4
test/fixtures/apps/agent-die/agent.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
setTimeout(() => {
|
||||
throw new Error('app worker throw');
|
||||
}, 5000);
|
||||
3
test/fixtures/apps/agent-die/package.json
vendored
Normal file
3
test/fixtures/apps/agent-die/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "agent-die"
|
||||
}
|
||||
13
test/fixtures/apps/agent-die/start.js
vendored
Normal file
13
test/fixtures/apps/agent-die/start.js
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const utils = require('../../../utils');
|
||||
|
||||
require('../../../../index').startCluster({
|
||||
baseDir: __dirname,
|
||||
workers: 1
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
process.exit();
|
||||
// coverage will be slow
|
||||
}, 5000);
|
||||
10
test/fixtures/apps/agent-instrument/agent.js
vendored
Normal file
10
test/fixtures/apps/agent-instrument/agent.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = agent => {
|
||||
const done = agent.readyCallback('custom-agent-ready')
|
||||
const ins = agent.instrument('http', `/hello`);
|
||||
setTimeout(() => {
|
||||
ins.end();
|
||||
done();
|
||||
}, 500);
|
||||
}
|
||||
3
test/fixtures/apps/agent-instrument/package.json
vendored
Normal file
3
test/fixtures/apps/agent-instrument/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "agent-instrument"
|
||||
}
|
||||
17
test/fixtures/apps/agent-restart/agent.js
vendored
Normal file
17
test/fixtures/apps/agent-restart/agent.js
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const client = require('./client');
|
||||
|
||||
module.exports = agent => {
|
||||
agent.startAgent({
|
||||
name: 'mock',
|
||||
client: client,
|
||||
subscribe: function(reg, listener) {
|
||||
console.log('agent subscribe', reg);
|
||||
},
|
||||
});
|
||||
|
||||
agent.messenger.on('die', () => {
|
||||
process.exit(1);
|
||||
});
|
||||
};
|
||||
14
test/fixtures/apps/agent-restart/app.js
vendored
Normal file
14
test/fixtures/apps/agent-restart/app.js
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const client = require('./client');
|
||||
|
||||
module.exports = app => {
|
||||
const mock = app.createAppWorkerClient('mock', {
|
||||
subscribe: function(info, listener) {
|
||||
this._subscribe(info, listener);
|
||||
return this;
|
||||
},
|
||||
});
|
||||
|
||||
mock.subscribe('aaa', data => console.log(data));
|
||||
};
|
||||
3
test/fixtures/apps/agent-restart/client.js
vendored
Normal file
3
test/fixtures/apps/agent-restart/client.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
ready: cb => cb(),
|
||||
};
|
||||
3
test/fixtures/apps/agent-restart/package.json
vendored
Normal file
3
test/fixtures/apps/agent-restart/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "agent-restart"
|
||||
}
|
||||
7
test/fixtures/apps/agent-throw/agent.js
vendored
Normal file
7
test/fixtures/apps/agent-throw/agent.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = agent => {
|
||||
agent.messenger.on('agent-throw', () => {
|
||||
throw new Error('agent error');
|
||||
});
|
||||
};
|
||||
8
test/fixtures/apps/agent-throw/app/router.js
vendored
Normal file
8
test/fixtures/apps/agent-throw/app/router.js
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
app.get('/agent-throw', function*() {
|
||||
app.messenger.broadcast('agent-throw');
|
||||
this.body = 'done';
|
||||
});
|
||||
};
|
||||
1
test/fixtures/apps/agent-throw/config/config.default.js
vendored
Normal file
1
test/fixtures/apps/agent-throw/config/config.default.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.keys = 'foo';
|
||||
3
test/fixtures/apps/agent-throw/package.json
vendored
Normal file
3
test/fixtures/apps/agent-throw/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "agent-throw"
|
||||
}
|
||||
9
test/fixtures/apps/aliyun-egg-app/app/controller/home.js
vendored
Normal file
9
test/fixtures/apps/aliyun-egg-app/app/controller/home.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function*() {
|
||||
this.body = {
|
||||
'aliyun-egg-core': !!this.app['aliyun-egg'],
|
||||
'aliyun-egg-plugin': !!this.app.custom,
|
||||
'aliyun-egg-agent': !!this.app.agent,
|
||||
}
|
||||
};
|
||||
5
test/fixtures/apps/aliyun-egg-app/app/router.js
vendored
Normal file
5
test/fixtures/apps/aliyun-egg-app/app/router.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
app.get('/', app.controller.home);
|
||||
};
|
||||
1
test/fixtures/apps/aliyun-egg-app/config/config.default.js
vendored
Normal file
1
test/fixtures/apps/aliyun-egg-app/config/config.default.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.keys = 'foo';
|
||||
3
test/fixtures/apps/aliyun-egg-app/package.json
vendored
Normal file
3
test/fixtures/apps/aliyun-egg-app/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "aliyun-egg-app"
|
||||
}
|
||||
3
test/fixtures/apps/aliyun-egg-biz/index.js
vendored
Normal file
3
test/fixtures/apps/aliyun-egg-biz/index.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('../aliyun-egg');
|
||||
3
test/fixtures/apps/aliyun-egg-biz/package.json
vendored
Normal file
3
test/fixtures/apps/aliyun-egg-biz/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "aliyun-egg-biz"
|
||||
}
|
||||
7
test/fixtures/apps/aliyun-egg/index.js
vendored
Normal file
7
test/fixtures/apps/aliyun-egg/index.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const egg = require('../../../..');
|
||||
|
||||
module.exports = egg;
|
||||
module.exports.Application = require('./lib/aliyun-egg');
|
||||
module.exports.Agent = require('./lib/agent');
|
||||
19
test/fixtures/apps/aliyun-egg/lib/agent.js
vendored
Normal file
19
test/fixtures/apps/aliyun-egg/lib/agent.js
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const egg = require('../../../../..');
|
||||
const Agent = egg.Agent;
|
||||
const AppWorkerLoader = egg.AppWorkerLoader;
|
||||
|
||||
class MyAgent extends Agent {
|
||||
|
||||
constructor(options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
get [Symbol.for('egg#eggPath')]() {
|
||||
return path.join(__dirname, '..');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MyAgent;
|
||||
37
test/fixtures/apps/aliyun-egg/lib/aliyun-egg.js
vendored
Normal file
37
test/fixtures/apps/aliyun-egg/lib/aliyun-egg.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const egg = require('../../../../..');
|
||||
const Application = egg.Application;
|
||||
const AppWorkerLoader = egg.AppWorkerLoader;
|
||||
|
||||
class Loader extends AppWorkerLoader {
|
||||
|
||||
constructor(options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
loadConfig() {
|
||||
this.loadServerConf();
|
||||
super.loadConfig();
|
||||
}
|
||||
|
||||
loadServerConf() {}
|
||||
}
|
||||
|
||||
class ChairApplication extends Application {
|
||||
|
||||
constructor(options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
get [Symbol.for('egg#eggPath')]() {
|
||||
return path.join(__dirname, '..');
|
||||
}
|
||||
|
||||
get [Symbol.for('egg#loader')]() {
|
||||
return Loader;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ChairApplication;
|
||||
5
test/fixtures/apps/aliyun-egg/lib/core/agent.js
vendored
Normal file
5
test/fixtures/apps/aliyun-egg/lib/core/agent.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = agent => {
|
||||
|
||||
};
|
||||
5
test/fixtures/apps/aliyun-egg/lib/core/app.js
vendored
Normal file
5
test/fixtures/apps/aliyun-egg/lib/core/app.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
app['aliyun-egg'] = {};
|
||||
};
|
||||
10
test/fixtures/apps/aliyun-egg/lib/core/config/plugin.js
vendored
Normal file
10
test/fixtures/apps/aliyun-egg/lib/core/config/plugin.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
custom: {
|
||||
enable: true,
|
||||
path: path.join(__dirname, '../../plugins/custom'),
|
||||
},
|
||||
};
|
||||
7
test/fixtures/apps/aliyun-egg/lib/plugins/custom/agent.js
vendored
Normal file
7
test/fixtures/apps/aliyun-egg/lib/plugins/custom/agent.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = agent => {
|
||||
agent.messenger.on('custom-aliyun-egg-worker', data => {
|
||||
agent.messenger.broadcast('custom-aliyun-egg-agent', data);
|
||||
})
|
||||
};
|
||||
9
test/fixtures/apps/aliyun-egg/lib/plugins/custom/app.js
vendored
Normal file
9
test/fixtures/apps/aliyun-egg/lib/plugins/custom/app.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
app.custom = {};
|
||||
app.messenger.broadcast('custom-aliyun-egg-worker', 123);
|
||||
app.messenger.on('custom-aliyun-egg-agent', data => {
|
||||
app.agent = data;
|
||||
})
|
||||
};
|
||||
3
test/fixtures/apps/aliyun-egg/package.json
vendored
Normal file
3
test/fixtures/apps/aliyun-egg/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "aliyun-egg"
|
||||
}
|
||||
13
test/fixtures/apps/app-die/app/router.js
vendored
Normal file
13
test/fixtures/apps/app-die/app/router.js
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
app.get('/exit', function*() {
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
app.get('/uncaughtException', function*() {
|
||||
setTimeout(() => {
|
||||
throw new Error('get uncaughtException');
|
||||
}, 100);
|
||||
});
|
||||
};
|
||||
1
test/fixtures/apps/app-die/config/config.default.js
vendored
Normal file
1
test/fixtures/apps/app-die/config/config.default.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.keys = 'foo';
|
||||
3
test/fixtures/apps/app-die/package.json
vendored
Normal file
3
test/fixtures/apps/app-die/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "app-die"
|
||||
}
|
||||
3
test/fixtures/apps/app-router/app/controller/home.js
vendored
Normal file
3
test/fixtures/apps/app-router/app/controller/home.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = function* () {
|
||||
this.body = 'hello';
|
||||
};
|
||||
4
test/fixtures/apps/app-router/app/router.js
vendored
Normal file
4
test/fixtures/apps/app-router/app/router.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = app => {
|
||||
app.get('home', '/', 'home');
|
||||
app.get('/home', app.controller.home);
|
||||
};
|
||||
3
test/fixtures/apps/app-router/package.json
vendored
Normal file
3
test/fixtures/apps/app-router/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "app-router"
|
||||
}
|
||||
7
test/fixtures/apps/app-server/app.js
vendored
Normal file
7
test/fixtures/apps/app-server/app.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
app.on('server', server => {
|
||||
app.serverEmit = true;
|
||||
});
|
||||
};
|
||||
5
test/fixtures/apps/app-server/app/router.js
vendored
Normal file
5
test/fixtures/apps/app-server/app/router.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
module.exports = app => {
|
||||
app.get('/', function* () {
|
||||
this.body = this.app.serverEmit;
|
||||
});
|
||||
};
|
||||
1
test/fixtures/apps/app-server/config/config.default.js
vendored
Normal file
1
test/fixtures/apps/app-server/config/config.default.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.keys = 'my keys';
|
||||
3
test/fixtures/apps/app-server/package.json
vendored
Normal file
3
test/fixtures/apps/app-server/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "app-server"
|
||||
}
|
||||
19
test/fixtures/apps/body_parser_testapp/app/router.js
vendored
Normal file
19
test/fixtures/apps/body_parser_testapp/app/router.js
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
module.exports = app => {
|
||||
app.get('/test/body_parser/user', function* () {
|
||||
this.body = {
|
||||
url: this.url,
|
||||
csrf: this.csrf
|
||||
};
|
||||
});
|
||||
|
||||
app.post('/test/body_parser/user', function* () {
|
||||
this.body = this.request.body;
|
||||
});
|
||||
|
||||
app.post('/test/body_parser/foo.json', function* () {
|
||||
this.body = this.request.body;
|
||||
});
|
||||
app.post('/test/body_parser/form.json', function* () {
|
||||
this.body = this.request.body;
|
||||
});
|
||||
};
|
||||
7
test/fixtures/apps/body_parser_testapp/config/config.default.js
vendored
Normal file
7
test/fixtures/apps/body_parser_testapp/config/config.default.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
exports.bodyParser = {
|
||||
queryString: {
|
||||
arrayLimit: 5
|
||||
}
|
||||
};
|
||||
|
||||
exports.keys = 'foo';
|
||||
3
test/fixtures/apps/body_parser_testapp/package.json
vendored
Normal file
3
test/fixtures/apps/body_parser_testapp/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "body_parser_testapp"
|
||||
}
|
||||
1
test/fixtures/apps/close-watcher-logrotator/config/config.default.js
vendored
Normal file
1
test/fixtures/apps/close-watcher-logrotator/config/config.default.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.keys = 'foo';
|
||||
2
test/fixtures/apps/close-watcher-logrotator/config/plugin.js
vendored
Normal file
2
test/fixtures/apps/close-watcher-logrotator/config/plugin.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
exports.logrotater = false;
|
||||
exports.watcher = false;
|
||||
3
test/fixtures/apps/close-watcher-logrotator/package.json
vendored
Normal file
3
test/fixtures/apps/close-watcher-logrotator/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "close-watcher-logrotator"
|
||||
}
|
||||
5
test/fixtures/apps/cluster_mod_app/app/controller/home.js
vendored
Normal file
5
test/fixtures/apps/cluster_mod_app/app/controller/home.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
exports.index = function* () {
|
||||
this.body = 'hi cluster';
|
||||
};
|
||||
5
test/fixtures/apps/cluster_mod_app/app/router.js
vendored
Normal file
5
test/fixtures/apps/cluster_mod_app/app/router.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
app.get('/', app.controller.home.index);
|
||||
};
|
||||
1
test/fixtures/apps/cluster_mod_app/config/config.default.js
vendored
Normal file
1
test/fixtures/apps/cluster_mod_app/config/config.default.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.keys = 'foo';
|
||||
3
test/fixtures/apps/cluster_mod_app/package.json
vendored
Normal file
3
test/fixtures/apps/cluster_mod_app/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "cluster_mod_app"
|
||||
}
|
||||
6
test/fixtures/apps/context-config-app/app/context.js
vendored
Normal file
6
test/fixtures/apps/context-config-app/app/context.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
foo: 1,
|
||||
bar: function() {
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
18
test/fixtures/apps/context-config-app/app/controller/home.js
vendored
Normal file
18
test/fixtures/apps/context-config-app/app/controller/home.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
exports.index = function* () {
|
||||
this.body = {
|
||||
path: this.router.pathFor('home'),
|
||||
foo: this.foo,
|
||||
bar: this.bar()
|
||||
};
|
||||
};
|
||||
|
||||
exports.runtime = function* () {
|
||||
this.runtime.mysql = 10;
|
||||
this.runtime.foo = 11;
|
||||
this.body = {
|
||||
mysql: this.runtime.mysql,
|
||||
foo: this.runtime.foo
|
||||
};
|
||||
};
|
||||
4
test/fixtures/apps/context-config-app/app/router.js
vendored
Normal file
4
test/fixtures/apps/context-config-app/app/router.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = app => {
|
||||
app.get('home', '/', 'home.index');
|
||||
app.get('runtime', '/runtime', 'home.runtime');
|
||||
};
|
||||
5
test/fixtures/apps/context-config-app/config/config.js
vendored
Normal file
5
test/fixtures/apps/context-config-app/config/config.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
exports.security = {
|
||||
csrf: false
|
||||
}
|
||||
|
||||
exports.keys = 'foo';
|
||||
5
test/fixtures/apps/context-config-app/config/config.local.js
vendored
Normal file
5
test/fixtures/apps/context-config-app/config/config.local.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
'use stirct';
|
||||
|
||||
exports.logger = {
|
||||
stdoutLevel: 'NONE',
|
||||
};
|
||||
3
test/fixtures/apps/context-config-app/package.json
vendored
Normal file
3
test/fixtures/apps/context-config-app/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "context-config-app"
|
||||
}
|
||||
13
test/fixtures/apps/cors/app/router.js
vendored
Normal file
13
test/fixtures/apps/cors/app/router.js
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
module.exports = app => {
|
||||
app.get('/', function*() {
|
||||
this.body = {
|
||||
foo: 'bar'
|
||||
};
|
||||
});
|
||||
|
||||
app.post('/', function*() {
|
||||
this.body = {
|
||||
foo: 'bar'
|
||||
};
|
||||
});
|
||||
};
|
||||
3
test/fixtures/apps/cors/config/config.default.js
vendored
Normal file
3
test/fixtures/apps/cors/config/config.default.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
exports.cors = {
|
||||
credentials: true,
|
||||
};
|
||||
1
test/fixtures/apps/cors/config/plugin.js
vendored
Normal file
1
test/fixtures/apps/cors/config/plugin.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.cors = true;
|
||||
3
test/fixtures/apps/cors/package.json
vendored
Normal file
3
test/fixtures/apps/cors/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "cors"
|
||||
}
|
||||
9
test/fixtures/apps/custom-env-app/app/router.js
vendored
Normal file
9
test/fixtures/apps/custom-env-app/app/router.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
app.get('/', function*() {
|
||||
this.body = {
|
||||
env: this.app.config.env,
|
||||
};
|
||||
});
|
||||
};
|
||||
3
test/fixtures/apps/custom-env-app/config/config.default.js
vendored
Normal file
3
test/fixtures/apps/custom-env-app/config/config.default.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
exports.keys = 'foo';
|
||||
3
test/fixtures/apps/custom-env-app/package.json
vendored
Normal file
3
test/fixtures/apps/custom-env-app/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "custom-env-app"
|
||||
}
|
||||
14
test/fixtures/apps/custom-logger/config/config.default.js
vendored
Normal file
14
test/fixtures/apps/custom-logger/config/config.default.js
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
module.exports = info => {
|
||||
return {
|
||||
customLogger: {
|
||||
myLogger: {
|
||||
file: path.join(info.baseDir, 'logs/my.log'),
|
||||
formatter: meta => meta.message,
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
3
test/fixtures/apps/custom-logger/package.json
vendored
Normal file
3
test/fixtures/apps/custom-logger/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "custom-logger"
|
||||
}
|
||||
6
test/fixtures/apps/demo/app/controller/hello.js
vendored
Normal file
6
test/fixtures/apps/demo/app/controller/hello.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function*() {
|
||||
this.setCookie('hi', 'foo');
|
||||
this.body = 'hello';
|
||||
};
|
||||
5
test/fixtures/apps/demo/app/controller/home.js
vendored
Normal file
5
test/fixtures/apps/demo/app/controller/home.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
module.exports = function* () {
|
||||
this.body = {
|
||||
workerTitle: process.title
|
||||
};
|
||||
};
|
||||
17
test/fixtures/apps/demo/app/controller/logger.js
vendored
Normal file
17
test/fixtures/apps/demo/app/controller/logger.js
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function*() {
|
||||
const message = this.query.message;
|
||||
|
||||
this.logger.debug('debug %s', message);
|
||||
this.logger.info('info %s', message);
|
||||
this.logger.warn('warn %s', message);
|
||||
this.logger.error(new Error('error ' + message));
|
||||
|
||||
this.coreLogger.debug('core debug %s', message);
|
||||
this.coreLogger.info('core info %s', message);
|
||||
this.coreLogger.warn('core warn %s', message);
|
||||
this.coreLogger.error(new Error('core error ' + message));
|
||||
|
||||
this.body = 'logger';
|
||||
};
|
||||
12
test/fixtures/apps/demo/app/router.js
vendored
Normal file
12
test/fixtures/apps/demo/app/router.js
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
module.exports = app => {
|
||||
app.get('home', '/', 'home');
|
||||
app.get('/hello', app.controller.hello);
|
||||
app.get('/logger', app.controller.logger);
|
||||
app.get('/protocol', function*() {
|
||||
this.body = this.protocol;
|
||||
});
|
||||
|
||||
app.get('/user.json', function*() {
|
||||
this.jsonp = { name: 'fengmk2' };
|
||||
});
|
||||
};
|
||||
2
test/fixtures/apps/demo/config/config.default.js
vendored
Normal file
2
test/fixtures/apps/demo/config/config.default.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
exports.keys = 'foo';
|
||||
exports.protocolHeaders = 'X-Forwarded-Proto';
|
||||
3
test/fixtures/apps/demo/package.json
vendored
Normal file
3
test/fixtures/apps/demo/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "demo"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user