Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for custom hostname instead of using localhost #377

Merged
merged 3 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ async function runServe(options: UserConfig) {
const server = require('./server').createServer(options)

let port = options.port || 3000
let hostname = options.hostname || 'localhost'
const protocol = options.https ? 'https' : 'http'

server.on('error', (e: Error & { code?: string }) => {
if (e.code === 'EADDRINUSE') {
console.log(`Port ${port} is in use, trying another one...`)
Expand All @@ -139,7 +141,7 @@ async function runServe(options: UserConfig) {
}
})

server.listen(port, () => {
server.listen(port, hostname, () => {
console.log()
console.log(` Dev server running at:`)
const interfaces = os.networkInterfaces()
Expand All @@ -151,7 +153,7 @@ async function runServe(options: UserConfig) {
type: detail.address.includes('127.0.0.1')
? 'Local: '
: 'Network: ',
host: detail.address.replace('127.0.0.1', 'localhost')
host: detail.address.replace('127.0.0.1', hostname)
}
})
.forEach(({ type, host }) => {
Expand All @@ -164,7 +166,7 @@ async function runServe(options: UserConfig) {

if (options.open) {
require('./utils/openBrowser').openBrowser(
`${protocol}://localhost:${port}`
`${protocol}://${hostname}:${port}`
)
}
})
Expand Down
1 change: 1 addition & 0 deletions src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export interface SharedConfig {
}

export interface ServerConfig extends SharedConfig {
hostname?: string
port?: number
open?: boolean
/**
Expand Down