Skip to content
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
2 changes: 1 addition & 1 deletion bin/bagdock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ program
.option('--ngrok', 'Use API URLs from .env.local (for ngrok tunnels)')
.hook('preAction', (_thisCommand, actionCommand) => {
const opts = program.opts()
if (opts.ngrok) loadLocalEnv()
setOutputMode({ json: opts.json, quiet: opts.quiet })
if (opts.ngrok) loadLocalEnv()
if (opts.apiKey) setApiKeyOverride(opts.apiKey)
if (opts.profile) setProfileOverride(opts.profile)
if (opts.env) {
Expand Down
13 changes: 11 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ export function getDashboardBase() { return _dashboardBase }
* in the current working directory. Used by the --ngrok flag to point
* the CLI at a local tunnel without hardcoding internal URLs.
*/
function normalizeUrl(raw: string): string {
let url = raw.replace(/^['"]|['"]$/g, '').replace(/\/+$/, '')
if (!/^https?:\/\//i.test(url)) {
console.error(chalk.red(`Invalid URL (must start with http:// or https://): ${raw}`))
process.exit(1)
}
return url
}

export function loadLocalEnv() {
const envPath = join(process.cwd(), '.env.local')
if (!existsSync(envPath)) {
Expand All @@ -51,9 +60,9 @@ export function loadLocalEnv() {
process.exit(1)
}

_apiBase = apiUrl
_apiBase = normalizeUrl(apiUrl)
if (vars['BAGDOCK_DASHBOARD_URL']) {
_dashboardBase = vars['BAGDOCK_DASHBOARD_URL']
_dashboardBase = normalizeUrl(vars['BAGDOCK_DASHBOARD_URL'])
}

console.log(chalk.dim(`Using local env → ${_apiBase}`))
Expand Down
Loading