Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 06a4aac

Browse files
merge: pull request #67 from CoolDeveloper101/master
Implementing --host flag for production.
2 parents 28b8654 + 2ebcf78 commit 06a4aac

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

cli/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ export default async function (appDir: string, options: Record<string, string |
2121
log.error(`invalid port '${options.port || options.p}'`)
2222
Deno.exit(1)
2323
}
24-
start(appDir, port, true, Boolean(options.r || options.reload))
24+
start(appDir, 'localhost', port, true, Boolean(options.r || options.reload))
2525
}

cli/start.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Usage:
88
if the <dir> is empty, the current directory will be used.
99
1010
Options:
11+
-hn, --hostname The address at which the server is to be started.
1112
-p, --port A port number to start the aleph.js app, default is 8080
1213
-L, --log-level Set log level [possible values: debug, info]
1314
-r, --reload Reload source code cache
@@ -16,10 +17,11 @@ Options:
1617

1718
export default async function (appDir: string, options: Record<string, string | boolean>) {
1819
const { start } = await import('../server.ts')
20+
const host = String(options.hn || options.hostname || 'localhost')
1921
const port = parseInt(String(options.p || options.port || '8080'))
2022
if (isNaN(port) || port <= 0 || !Number.isInteger(port)) {
2123
log.error(`invalid port '${options.port || options.p}'`)
2224
Deno.exit(1)
2325
}
24-
start(appDir, port, false, Boolean(options.r || options.reload))
26+
start(appDir, host, port, false, Boolean(options.r || options.reload))
2527
}

server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { injectHmr, Project } from './project.ts'
77
import { path, serve, ws } from './std.ts'
88
import util, { hashShort } from './util.ts'
99

10-
export async function start(appDir: string, port: number, isDev = false, reload = false) {
10+
export async function start(appDir: string, hostname: string, port: number, isDev = false, reload = false) {
1111
const project = new Project(appDir, isDev ? 'development' : 'production', reload)
1212
await project.ready
1313

1414
while (true) {
1515
try {
16-
const s = serve({ port })
17-
log.info(`Server ready on http://localhost:${port}`)
16+
const s = serve({ hostname, port })
17+
log.info(`Server ready on http://${hostname}:${port}`)
1818
for await (const req of s) {
1919
const url = new URL('http://localhost/' + req.url)
2020
const pathname = util.cleanPath(url.pathname)

0 commit comments

Comments
 (0)