Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ $ eggctl stop [options]

In addition to the command line specification, options can also be specified in `package.json`. However, the command line designation takes precedence.

```json
```js
{
"eggScriptsConfig": {
"port": 1234,
"ignore-stderr": true
"ignore-stderr": true,
// will pass as `node --max-http-header-size=20000`
"node-options--max-http-header-size": "20000"
}
}
```
Expand All @@ -108,4 +110,4 @@ Please open an issue [here](https://github.com/eggjs/egg/issues?q=is%3Aissue+is%

This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Tue Mar 08 2022 09:52:13 GMT+0800`.

<!-- GITCONTRIBUTOR_END -->
<!-- GITCONTRIBUTOR_END -->
14 changes: 13 additions & 1 deletion lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,19 @@ class Command extends BaseCommand {
// read argv from eggScriptsConfig in package.json
if (eggScriptsConfig && typeof eggScriptsConfig === 'object') {
for (const key in pkgInfo.eggScriptsConfig) {
if (argv[key] == null) argv[key] = pkgInfo.eggScriptsConfig[key];
const v = pkgInfo.eggScriptsConfig[key];
// like https://github.com/node-modules/common-bin/blob/master/lib/helper.js#L180
if (key.startsWith('node-options--')) {
const newKey = key.replace('node-options--', '');
if (execArgvObj[newKey] == null) {
execArgvObj[newKey] = v;
}
} else {
if (argv[key] == null) {
// only set if key is not pass from command line
argv[key] = v;
}
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/egg-scripts-node-options/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = () => {
console.log('process.execArgv:', process.execArgv);
console.log('maxHeaderSize:', require('http').maxHeaderSize);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

exports.keys = '123456';
11 changes: 11 additions & 0 deletions test/fixtures/egg-scripts-node-options/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "example",
"version": "1.0.0",
"dependencies": {
"egg": "^1.0.0"
},
"eggScriptsConfig": {
"workers": 1,
"node-options--max-http-header-size": "20000"
}
}
26 changes: 26 additions & 0 deletions test/start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,32 @@ describe('test/start.test.js', () => {
});
});

describe('read eggScriptsConfig', () => {
let app;
let fixturePath;

before(function* () {
fixturePath = path.join(__dirname, 'fixtures/egg-scripts-node-options');
yield utils.cleanup(fixturePath);
});

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

it('should start', function* () {
app = coffee.fork(eggBin, [ 'start', '--workers=1', fixturePath ]);
app.debug();
app.expect('code', 0);

yield sleep(waitTime);

assert(app.stderr === '');
assert(app.stdout.match(/maxHeaderSize: 20000/));
});
});

describe('subDir as baseDir', () => {
let app;
const rootDir = path.join(__dirname, '..');
Expand Down