Skip to content

Commit f116018

Browse files
committed
add host config for preview
1 parent 7bc2d82 commit f116018

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

src/commands/preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const preview = async () => {
1515
const address = server.address();
1616
if (address && typeof address !== "string") {
1717
const open = (await import("open")).default;
18-
await open(`http://localhost:${address.port}`);
18+
await open(`http://${address.address}:${address.port}`);
1919
}
2020

2121
startLocalChangeWatcher({

src/lib/config.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ describe("config", () => {
224224
beforeEach(() => {
225225
const userConfigData = {
226226
includePrivate: true,
227+
host: "localhost",
227228
port: 9999,
228229
};
229230
resetFiles();
@@ -234,6 +235,7 @@ describe("config", () => {
234235
const userConfig = await config.getUserConfig();
235236
expect(userConfig).toStrictEqual({
236237
includePrivate: true,
238+
host: "localhost",
237239
port: 9999,
238240
});
239241
});
@@ -248,6 +250,7 @@ describe("config", () => {
248250
const userConfig = await config.getUserConfig();
249251
expect(userConfig).toStrictEqual({
250252
includePrivate: false,
253+
host: "localhost",
251254
port: 8888,
252255
});
253256
});

src/lib/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface Options {
1414

1515
type UserConfig = {
1616
includePrivate: boolean;
17+
host: string;
1718
port: number;
1819
};
1920

@@ -107,6 +108,7 @@ class Config {
107108
async getUserConfig() {
108109
const defaultConfig = {
109110
includePrivate: false,
111+
host: "localhost",
110112
port: 8888,
111113
} as UserConfig;
112114

src/server/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export async function startServer() {
3232

3333
const server = createServer(app);
3434
const userConfig = await config.getUserConfig();
35+
const host = userConfig.host;
3536
const port = userConfig.port;
36-
const host = "localhost";
3737

3838
return new Promise<Server>((resolve, reject) => {
3939
server

0 commit comments

Comments
 (0)