Skip to content

Commit 60638cf

Browse files
committed
feat: add env.port & env.host
1 parent a8cbbd3 commit 60638cf

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/plugins/factory/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@ module.exports = async function(api, info = {}) {
1717
}
1818
});
1919

20+
// 上下文参数
21+
const apiContext = api.context || {};
22+
2023
const { index, port, host } = info;
2124
const runApp = require(index); // app.js
2225
await runApp(app);
2326

2427
const portfinder = require('portfinder');
2528

26-
const startPort = parseInt(process.env.PORT || port || 3000);
29+
const startPort = parseInt(process.env.PORT || apiContext.port || port || 3000);
2730
const _port = await portfinder.getPortPromise({
2831
port: startPort, // minimum port
2932
stopPort: startPort + 300, // maximum port
3033
});
3134

32-
const _host = process.env.HOST || host || '0.0.0.0';
35+
const _host = process.env.HOST || apiContext.host || host || '0.0.0.0';
3336

3437
return new Promise((resolve, reject) => {
3538
app.listen(_port, _host, err => {

0 commit comments

Comments
 (0)