Skip to content

Commit 790e4c3

Browse files
committed
Update: Address
1 parent e4d8904 commit 790e4c3

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/commands/preview.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { config } from "../lib/config";
22
import { getFileSystemRepo } from "../lib/get-file-system-repo";
33
import { getQiitaApiInstance } from "../lib/get-qiita-api-instance";
4+
import { getUrlAddress } from "../lib/getUrlAddress";
45
import { syncArticlesFromQiita } from "../lib/sync-articles-from-qiita";
56
import { startLocalChangeWatcher, startServer } from "../server/app";
67

@@ -13,9 +14,11 @@ export const preview = async () => {
1314
const server = await startServer();
1415

1516
const address = server.address();
16-
if (address && typeof address !== "string") {
17+
const url = getUrlAddress(address);
18+
19+
if (url) {
1720
const open = (await import("open")).default;
18-
await open(`http://localhost:${address.port}`);
21+
await open(url);
1922
}
2023

2124
startLocalChangeWatcher({

src/server/app.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { EmojiRouter } from "./api/emoji";
1010
import { ItemsRouter } from "./api/items";
1111
import { ReadmeRouter } from "./api/readme";
1212
import { config } from "../lib/config";
13+
import { getUrlAddress } from "../lib/getUrlAddress";
1314

1415
export async function startServer() {
1516
const app = express();
@@ -39,7 +40,11 @@ export async function startServer() {
3940
server
4041
.listen(port, host)
4142
.once("listening", () => {
42-
console.log(`Preview: http://${host}:${port}`);
43+
const address = server.address();
44+
const url = getUrlAddress(address);
45+
if (url) {
46+
console.log(`Preview: ${url}`)
47+
}
4348

4449
resolve(server);
4550
})

0 commit comments

Comments
 (0)