Skip to content

Commit 40e45d8

Browse files
committed
Include port number from env variable
1 parent fae3747 commit 40e45d8

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

bin.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/env node
22
require("yargs")
3-
.scriptName("httpserver")
3+
.scriptName("http-server")
44
.command({
55
command: "start",
66
desc: ":start http server",
77
handler: () => require("./server.js"),
88
})
99
.demandCommand()
1010
.argv.toString();
11-

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"name": "http-server",
3-
"version": "1.0.0",
2+
"name": "@nucleoidjs/http-server",
3+
"version": "0.0.0",
44
"description": "Create http-server with basename for SPA Projects.",
55
"bin": {
66
"http-server": "bin.js"
77
},
88
"scripts": {
99
"start": "node bin.js start",
10-
"test": "echo \"Error: no test specified\" && exit 1"
10+
"test": "exit 0"
1111
},
1212
"repository": {
1313
"type": "git",

server.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,20 @@ import(`${configPath}/config.js`).then((module) => {
88
const config = module.default;
99

1010
app.use(
11-
config.base,
12-
express.static(path.join(fileURLToPath(configPath), "dist"))
11+
config.base,
12+
express.static(path.join(fileURLToPath(configPath), "dist")),
1313
);
1414

1515
app.get("*", (req, res) => {
1616
res.sendFile(path.join(fileURLToPath(configPath), "dist", "index.html"));
1717
});
1818

19-
app.listen(config.port || 3000, () => {
19+
const port = process.env.PORT || config.port || 3000;
20+
21+
app.listen(port, () => {
2022
console.log(
21-
`\x1b[36m%s\x1b[0m`,
22-
`Server is running on port http://localhost:${config.port || 3000}${
23-
config.base
24-
}`
23+
`\x1b[36m%s\x1b[0m`,
24+
`Server running on port ${port} with base ${config.base}`,
2525
);
2626
});
2727
});
28-

0 commit comments

Comments
 (0)