fix: consider --host flag and HOST env variable (#9912)

This commit is contained in:
Harminder Virk authored and GitHub committed 2024-11-04 14:56:57 +05:30
1 parent dd93d8de6e
commit 300ef8dbb9
2 files changed
+20 -10

No files matched your search

+8 -4
View File
@@ -290,8 +290,10 @@ function buildLocalCommands(cli, isLocalProject) {
.option(`H`, { .option(`H`, {
alias: `host`, alias: `host`,
type: `string`, type: `string`,
default: defaultHost, default: process.env.HOST || defaultHost,
describe: `Set host. Defaults to ${defaultHost}`, describe: process.env.HOST
? `Set host. Defaults to ${process.env.HOST} (set by env.HOST) (otherwise defaults ${defaultHost})`
: `Set host. Defaults to ${defaultHost}`,
}) })
.option(`p`, { .option(`p`, {
alias: `port`, alias: `port`,
@@ -326,8 +328,10 @@ function buildLocalCommands(cli, isLocalProject) {
.option(`H`, { .option(`H`, {
alias: `host`, alias: `host`,
type: `string`, type: `string`,
default: defaultHost, default: process.env.HOST || defaultHost,
describe: `Set host. Defaults to ${defaultHost}`, describe: process.env.HOST
? `Set host. Defaults to ${process.env.HOST} (set by env.HOST) (otherwise defaults ${defaultHost})`
: `Set host. Defaults to ${defaultHost}`,
}) })
.option(`p`, { .option(`p`, {
alias: `port`, alias: `port`,
+12 -6
View File
@@ -59,9 +59,11 @@ export async function registerInstrumentation(directory: string) {
export var traceRequestHandler: (...args: any[]) => Promise<any> = void 0 as any export var traceRequestHandler: (...args: any[]) => Promise<any> = void 0 as any
function displayAdminUrl({ function displayAdminUrl({
container, host,
port, port,
container,
}: { }: {
host: string
port: string | number port: string | number
container: MedusaContainer container: MedusaContainer
}) { }) {
@@ -82,16 +84,17 @@ function displayAdminUrl({
return return
} }
logger.info(`Admin URL → http://localhost:${port}${adminPath}`) logger.info(`Admin URL → http://${host}:${port}${adminPath}`)
} }
async function start(args: { async function start(args: {
directory: string directory: string
host?: string
port?: number port?: number
types?: boolean types?: boolean
cluster?: number cluster?: number
}) { }) {
const { port = 9000, directory, types } = args const { port = 9000, host = "localhost", directory, types } = args
async function internalStart(generateTypes: boolean) { async function internalStart(generateTypes: boolean) {
track("CLI_START") track("CLI_START")
@@ -136,9 +139,12 @@ async function start(args: {
const serverActivity = logger.activity(`Creating server`) const serverActivity = logger.activity(`Creating server`)
const server = GracefulShutdownServer.create( const server = GracefulShutdownServer.create(
http_.listen(port).on("listening", () => { http_.listen(port, host).on("listening", () => {
logger.success(serverActivity, `Server is ready on port: ${port}`) logger.success(
displayAdminUrl({ container, port }) serverActivity,
`Server is ready on http://${host}:${port}`
)
displayAdminUrl({ container, host, port })
track("CLI_START_COMPLETED") track("CLI_START_COMPLETED")
}) })
) )