Skip to content

Commit

Permalink
Merge pull request Alethio#64 from Alethio/fix-open-browser
Browse files Browse the repository at this point in the history
Update opn library and add error handling
  • Loading branch information
use-strict authored Dec 6, 2019
2 parents 1c65cb1 + 45f0853 commit 219f24f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
10 changes: 7 additions & 3 deletions dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as express from "express";
import * as path from "path";
import * as fs from "fs";
import * as morgan from "morgan";
import opn = require("opn");
import open = require("open");
import { AddressInfo } from "net";

const basePath = process.env.APP_BASE_PATH ?
Expand All @@ -26,9 +26,13 @@ app.use(`${basePath}plugins`, express.static(path.resolve("../dist/plugins"), {
// Fallback for HTML 5 routing
app.use(`${basePath}*`, (req, res) => res.sendFile(path.resolve("../dist/index.html")));

let server = app.listen(Number(process.env.PORT) || 3000, process.env.HOST || "127.0.0.1", () => {
let server = app.listen(Number(process.env.PORT) || 3000, process.env.HOST || "127.0.0.1", async () => {
let address = server.address() as AddressInfo;
process.stdout.write(`Listening on ${address.address + ":" + address.port}\n`);

opn(`http://localhost:${address.port}${basePath}`);
try {
await open(`http://localhost:${address.port}${basePath}`);
} catch (e) {
process.stderr.write(`\nFailed to open web browser. You can open it yourself and ignore this error. ${e}`);
}
});
16 changes: 8 additions & 8 deletions dev/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"express": "^4.16.3",
"jsonc-parser": "^2.0.3",
"morgan": "^1.9.1",
"opn": "^5.3.0",
"open": "^7.0.0",
"ts-node": "^6.1.0",
"typescript": "^3.0.1"
}
Expand Down

0 comments on commit 219f24f

Please sign in to comment.