mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
feat: add --host and --port CLI arguments to hapi server command. fix #37
Add configurable host binding for the Mini App HTTP server through: - New `webappHost` configuration (defaults to 127.0.0.1 for security) - CLI arguments `--host` and `--port` with flexible parsing (--host=value or --host value) - Priority order: CLI args > env vars > settings.json > defaults - Updated Bun.serve() to bind to the configured hostname Modified: - server/src/config/settings.ts - server/src/config/serverSettings.ts - server/src/configuration.ts - server/src/web/server.ts - server/src/index.ts - cli/src/commands/server.ts
This commit is contained in:
@@ -1,11 +1,39 @@
|
||||
import chalk from 'chalk'
|
||||
import type { CommandDefinition } from './types'
|
||||
import type { CommandDefinition, CommandContext } from './types'
|
||||
|
||||
function parseServerArgs(args: string[]): { host?: string; port?: string } {
|
||||
const result: { host?: string; port?: string } = {}
|
||||
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i]
|
||||
if (arg === '--host' && i + 1 < args.length) {
|
||||
result.host = args[++i]
|
||||
} else if (arg === '--port' && i + 1 < args.length) {
|
||||
result.port = args[++i]
|
||||
} else if (arg.startsWith('--host=')) {
|
||||
result.host = arg.slice('--host='.length)
|
||||
} else if (arg.startsWith('--port=')) {
|
||||
result.port = arg.slice('--port='.length)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
export const serverCommand: CommandDefinition = {
|
||||
name: 'server',
|
||||
requiresRuntimeAssets: false,
|
||||
run: async () => {
|
||||
run: async (context: CommandContext) => {
|
||||
try {
|
||||
const { host, port } = parseServerArgs(context.commandArgs)
|
||||
|
||||
if (host) {
|
||||
process.env.WEBAPP_HOST = host
|
||||
}
|
||||
if (port) {
|
||||
process.env.WEBAPP_PORT = port
|
||||
}
|
||||
|
||||
await import('../../../server/src/index')
|
||||
} catch (error) {
|
||||
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error')
|
||||
|
||||
Reference in New Issue
Block a user