Skip to content

Commit

Permalink
feat: use appInfo.root in config (eggjs#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore authored and fengmk2 committed Nov 9, 2016
1 parent ea71515 commit c736ac9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
8 changes: 3 additions & 5 deletions config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
const fs = require('fs');
const path = require('path');

// https://github.com/eggjs/egg-core#appinfo
module.exports = appInfo => {
// appInfo contains name, baseDir, env, HOME, and pkg

const appRoot = appInfo.env === 'local' || appInfo.env === 'unittest' ? appInfo.baseDir : appInfo.HOME;

const exports = {

Expand Down Expand Up @@ -145,8 +143,8 @@ module.exports = appInfo => {
* @property {Object} coreLogger - core logger 的自定义配置
*/
exports.logger = {
dir: path.join(appRoot, 'logs', appInfo.name),
rotateLogDirs: [ path.join(appRoot, 'logs', appInfo.name) ],
dir: path.join(appInfo.root, 'logs', appInfo.name),
rotateLogDirs: [ path.join(appInfo.root, 'logs', appInfo.name) ],
encoding: 'utf8',
env: appInfo.env,
level: 'INFO',
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
"accepts": "^1.3.3",
"agentkeepalive": "^2.2.0",
"co": "^4.6.0",
"debug": "^2.2.0",
"debug": "^2.3.0",
"delegates": "^1.0.0",
"egg-cluster": "^1.0.0",
"egg-cookies": "^1.0.0",
"egg-core": "^1.0.0",
"egg-core": "^1.1.0",
"egg-cors": "^1.0.0",
"egg-development": "^1.0.2",
"egg-i18n": "^1.0.2",
"egg-logger": "^1.4.0",
"egg-logrotator": "^2.2.2",
"egg-multipart": "^1.0.0",
"egg-onerror": "^1.0.0",
"egg-onerror": "^1.1.0",
"egg-rest": "^1.1.0",
"egg-schedule": "^2.2.1",
"egg-security": "^1.2.1",
Expand Down Expand Up @@ -75,7 +75,7 @@
"moment": "^2.15.2",
"mz": "^2.4.0",
"npminstall": "^2.1.1",
"nunjucks": "^2.5.2",
"nunjucks": "^3.0.0",
"once": "^1.3.3",
"pedding": "^1.0.0",
"rds": "^0.1.0",
Expand Down
30 changes: 24 additions & 6 deletions test/lib/core/loader/config_loader.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
'use strict';

const path = require('path');
const mm = require('egg-mock');
const utils = require('../../../utils');

describe('test/lib/core/loader/config_loader.test.js', () => {
let app;
before(() => {
app = utils.app('apps/demo');
return app.ready();
});
after(() => app.close());
const home = utils.getFilepath('apps/demo/logs/home');
afterEach(() => app.close());
afterEach(mm.restore);

it('should get middlewares', () => {
it('should get middlewares', function* () {
app = utils.app('apps/demo');
yield app.ready();
app.config.coreMiddleware.slice(0, 5).should.eql([
'meta',
'siteFile',
Expand All @@ -19,4 +21,20 @@ describe('test/lib/core/loader/config_loader.test.js', () => {
'overrideMethod',
]);
});

it('should get logger dir when unittest', function* () {
mm(process.env, 'EGG_HOME', home);
mm(process.env, 'EGG_SERVER_ENV', 'unittest');
app = utils.app('apps/demo');
yield app.ready();
app.config.logger.dir.should.eql(utils.getFilepath('apps/demo/logs/demo'));
});

it('should get logger dir when default', function* () {
mm(process.env, 'EGG_HOME', home);
mm(process.env, 'EGG_SERVER_ENV', 'default');
app = utils.app('apps/demo');
yield app.ready();
app.config.logger.dir.should.eql(path.join(home, 'logs/demo'));
});
});

0 comments on commit c736ac9

Please sign in to comment.