forked from anomalyco/sst
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.js
More file actions
43 lines (39 loc) · 1.07 KB
/
Copy pathconsole.js
File metadata and controls
43 lines (39 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const {
getChildLogger,
useLocalServer,
Runtime,
} = require("@serverless-stack/core");
const detect = require("detect-port-alt");
const chalk = require("chalk");
const logger = getChildLogger("client");
module.exports = async function (_argv, config) {
const local = useLocalServer({
port: await chooseServerPort(13557),
app: config.name,
stage: config.stage,
region: config.region,
live: false,
});
new Runtime.Server({
port: await chooseServerPort(12557),
}).listen();
logger.info(
`SST Console: https://console.serverless-stack.com/${config.name}/${
config.stage
}/stacks${local.port !== 13557 ? "?_port=" + local.port : ""}`
);
};
async function chooseServerPort(defaultPort) {
const host = "0.0.0.0";
logger.debug(`Checking port ${defaultPort} on host ${host}`);
try {
return detect(defaultPort, host);
} catch (err) {
throw new Error(
chalk.red(`Could not find an open port at ${chalk.bold(host)}.`) +
"\n" +
("Network error message: " + err.message || err) +
"\n"
);
}
}