Permalink
Browse files

fix(devServer): reset port when app get port from agent (#28)

<!--
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. -->
  • Loading branch information...
popomore committed Jan 8, 2019
1 parent a5866bc commit f5966eca57fcfe5819617e264555ba00c9c6c95b
1 app.js
@@ -13,6 +13,7 @@ module.exports = app => {
if (assetsConfig.devServer.autoPort === true) {
try {
port = fs.readFileSync(assetsConfig.devServer.portPath, 'utf8');
assetsConfig.devServer.port = Number(port);
} catch (err) {
// istanbul ignore next
throw new Error('check autoPort fail');
@@ -171,7 +171,11 @@ describe('test/dev_server.test.js', () => {

await app1.httpRequest()
.get('/')
.expect(/http:\/\/127.0.0.1:\d+\/index.js/)
.expect(/http:\/\/127.0.0.1:10000\/index.js/)
.expect(200);
await app1.httpRequest()
.get('/port')
.expect('10000')
.expect(200);

app1.expect('stdout', /\[server] listening 10000/);
@@ -6,6 +6,10 @@ class HomeController extends Controller {
async index() {
await this.ctx.render('index.js');
}

async port() {
this.ctx.body = this.app.config.assets.devServer.port;
}
}

module.exports = HomeController;
@@ -4,4 +4,5 @@ module.exports = app => {
const { router, controller } = app;

router.get('/', controller.home.index);
router.get('/port', controller.home.port);
};

0 comments on commit f5966ec

Please sign in to comment.