Skip to content

Commit

Permalink
feat: remove env default value (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 committed Aug 16, 2017
1 parent eb35abd commit 8703ad4
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 7 deletions.
24 changes: 24 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,24 @@
<!--
Thank you for your pull request. Please review below requirements.
Bug fixes and new features should include tests and possibly benchmarks.
Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md
感谢您贡献代码。请确认下列 checklist 的完成情况。
Bug 修复和新功能必须包含测试,必要时请附上性能测试。
Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md
-->

##### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [ ] `npm test` passes
- [ ] tests and/or benchmarks are included
- [ ] documentation is changed or added
- [ ] commit message follows commit guidelines

##### Affected core subsystem(s)
<!-- Provide affected core subsystem(s). -->


##### Description of change
<!-- Provide a description of the change below this comment. -->
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -48,13 +48,13 @@ $ egg-scripts start [options] [baseDir]
- `workers` - numbers of app workers, default to `process.env.EGG_WORKERS`, if unset, egg will use `os.cpus().length` as default.
- `daemon` - whether run at background daemon mode.
- `framework` - specify framework that can be absolute path or npm package, default to auto detect.
- `env` - egg server env, default to `process.env.EGG_SERVER_ENV || prod`.
- `env` - egg server env, default to `process.env.EGG_SERVER_ENV`, recommended to keep empty then use framwork default env.

### stop

Stop egg gracefull.

**Note: ** Windows is not supported, try to kill master process which command contains `start-cluster` or `--type=egg-server` yourself, good luck.
**Note:** Windows is not supported yet, try to kill master process which command contains `start-cluster` or `--type=egg-server` yourself, good luck.

```bash
# stop egg
Expand Down
6 changes: 3 additions & 3 deletions lib/cmd/start.js
Expand Up @@ -33,8 +33,8 @@ class StartCommand extends Command {
default: process.env.PORT,
},
env: {
description: 'egg server env, default to `process.env.EGG_SERVER_ENV || prod`',
default: process.env.EGG_SERVER_ENV || 'prod',
description: 'egg server env, default to `process.env.EGG_SERVER_ENV`',
default: process.env.EGG_SERVER_ENV,
},
framework: {
description: 'specify framework that can be absolute path or npm package',
Expand Down Expand Up @@ -73,7 +73,7 @@ class StartCommand extends Command {
env.HOME = homedir();
env.NODE_ENV = 'production';

// cli argv > process.env.EGG_SERVER_ENV > default to prod
// cli argv -> process.env.EGG_SERVER_ENV -> `undefined` then egg will use `prod`
env.EGG_SERVER_ENV = argv.env;
argv.env = undefined;

Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -7,7 +7,7 @@
"egg-scripts": "bin/egg-scripts.js"
},
"dependencies": {
"common-bin": "^2.4.0",
"common-bin": "^2.5.0",
"egg-utils": "^2.2.0",
"moment": "^2.18.1",
"mz": "^2.6.0",
Expand All @@ -22,8 +22,9 @@
"egg": "^1.7.0",
"egg-bin": "^4.1.0",
"egg-ci": "^1.8.0",
"eslint": "^4.3.0",
"eslint": "^4.4.1",
"eslint-config-egg": "^5.0.0",
"mm": "^2.1.0",
"urllib": "^2.24.0",
"webstorm-disable-index": "^1.2.0"
},
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/example/node_modules/custom-framework/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions test/start.test.js
Expand Up @@ -9,6 +9,7 @@ const mkdirp = require('mz-modules/mkdirp');
const coffee = require('coffee');
const homedir = require('node-homedir');
const httpclient = require('urllib');
const mm = require('mm');
const utils = require('./utils');

describe('test/start.test.js', () => {
Expand All @@ -18,6 +19,8 @@ describe('test/start.test.js', () => {
const logDir = path.join(homePath, 'logs/example');
const waitTime = '10s';

afterEach(() => mm.restore);

describe('start without daemon', () => {
describe('full path', () => {
let app;
Expand Down Expand Up @@ -202,6 +205,34 @@ describe('test/start.test.js', () => {
assert(result.data.toString() === 'pre, true');
});
});

describe('custom env', () => {
let app;

before(function* () {
yield utils.cleanup(fixturePath);
});

after(function* () {
app.proc.kill('SIGTERM');
yield utils.cleanup(fixturePath);
});

it('should start', function* () {
mm(process.env, 'CUSTOM_ENV', 'pre');
app = coffee.fork(eggBin, [ 'start', '--workers=2', fixturePath ]);
app.debug();
app.expect('code', 0);

yield sleep(waitTime);

assert(app.stderr === '');
assert(app.stdout.includes('## CUSTOM_ENV: pre'));
assert(app.stdout.match(/custom-framework started on http:\/\/127\.0\.0\.1:7001/));
const result = yield httpclient.request('http://127.0.0.1:7001/env');
assert(result.data.toString() === 'pre, true');
});
});
});

describe('start with daemon', () => {
Expand Down

0 comments on commit 8703ad4

Please sign in to comment.