Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit f2f13b0

Browse files
committed
feat: add port and hostname option to config
it defaults to 5173 and localhost
1 parent 6ce9471 commit f2f13b0

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ import { defineConfig } from '@bistroo/vue-ssr'
3939
import { fileURLToPath } from 'node:url'
4040

4141
export default defineConfig({
42-
devPort: 5173,
43-
startPort: 6173,
4442
vite: {
4543
resolve: {
4644
alias: {

example/vue-ssr.config.ts

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { defineConfig } from '@bistroo/vue-ssr'
22
import { fileURLToPath } from 'node:url'
33

44
export default defineConfig({
5-
devPort: 1234,
6-
startPort: 1234,
75
vite: {
86
resolve: {
97
alias: {

src/cli.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const command = args._[0];
1414
if (command === 'build') {
1515
await build(config?.vite)
1616
} else if (command === 'start') {
17-
await start(config?.startPort ?? 5173)
17+
await start(config?.port ?? 5173, config?.hostname ?? 'localhost')
1818
} else {
19-
await dev({ port: config?.devPort ?? 6173, viteConfig: config?.vite })
19+
await dev({ port: config?.port ?? 5173, hostname: config?.hostname ?? 'localhost', viteConfig: config?.vite })
2020
}

src/node/dev.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { vueSsrPlugin } from '../vue/plugin'
1313

1414
const __dirname = dirname(fileURLToPath(import.meta.url))
1515

16-
export async function dev({ port, viteConfig: viteConfig }: { port: number, viteConfig?: UserConfig }) {
16+
export async function dev({ port, hostname, viteConfig: viteConfig }: { port: number, hostname: string, viteConfig?: UserConfig }) {
1717
const manifest = {}
1818

1919
const vite = await createServer(mergeConfig({
@@ -115,7 +115,7 @@ export async function dev({ port, viteConfig: viteConfig }: { port: number, vite
115115
}
116116
})
117117

118-
app.listen(port, () => {
119-
console.log(`http://localhost:${port}`)
118+
app.listen(port, hostname, () => {
119+
console.log(`http://${hostname}:${port}`)
120120
})
121121
}

src/node/start.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import cookieParser from 'cookie-parser'
77
import { load } from 'cheerio'
88
import { type HeadTag } from '@vueuse/head'
99

10-
export async function start(port: number) {
10+
export async function start(port: number, hostname: string) {
1111
const template = fs.readFileSync(join(cwd(), 'dist/client/index.html'), 'utf-8')
1212

1313
const manifest = JSON.parse(
@@ -95,7 +95,7 @@ export async function start(port: number) {
9595
res.status(200).set({ 'Content-Type': 'text/html' }).end($.html())
9696
})
9797

98-
app.listen(port, () => {
99-
console.log(`http://localhost:${port}`)
98+
app.listen(port, hostname, () => {
99+
console.log(`http://${hostname}:${port}`)
100100
})
101101
}

src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { Request, Response } from 'express'
55

66
export type VueSsrConfig = {
77
vite?: UserConfig
8-
devPort?: number
9-
startPort?: number
8+
port?: number
9+
hostname?: string
1010
}
1111

1212
export type State = { value?: any }

0 commit comments

Comments
 (0)