UNPKG

@heroku-cli/command

Version:
72 lines (71 loc) 2.46 kB
import { ux } from '@oclif/core'; import * as url from 'node:url'; import { ALLOWED_HEROKU_DOMAINS, LOCALHOST_DOMAINS } from './api-client.js'; export class Vars { get apiHost() { if (this.host.startsWith('http')) { const u = url.parse(this.host); if (u.host) return u.host; } return `api.${this.host}`; } get apiUrl() { return this.host.startsWith('http') ? this.host : `https://api.${this.host}`; } get envGitHost() { return process.env.HEROKU_GIT_HOST; } get envHost() { return process.env.HEROKU_HOST; } get envParticleboardUrl() { return process.env.HEROKU_PARTICLEBOARD_URL; } get gitHost() { if (this.envGitHost) return this.envGitHost; if (this.host.startsWith('http')) { const u = url.parse(this.host); if (u.host) return u.host; } return this.host; } get gitPrefixes() { return [`git@${this.gitHost}:`, `ssh://git@${this.gitHost}/`, `https://${this.httpGitHost}/`]; } get host() { const { envHost } = this; if (envHost && !this.isValidHerokuHost(envHost)) { ux.warn(`Invalid HEROKU_HOST '${envHost}' - using default`); return 'heroku.com'; } return envHost || 'heroku.com'; } get httpGitHost() { if (this.envGitHost) return this.envGitHost; if (this.host.startsWith('http')) { const u = url.parse(this.host); if (u.host) return u.host; } return `git.${this.host}`; } // This should be fixed after we make our staging hostnames consistent throughout all services // changing the staging cloud URL to `particleboard.staging.herokudev.com`. get particleboardUrl() { if (this.envParticleboardUrl) return this.envParticleboardUrl; return process.env.HEROKU_CLOUD === 'staging' ? 'https://particleboard-staging-cloud.herokuapp.com' : 'https://particleboard.heroku.com'; } isValidHerokuHost(host) { // Remove protocol if present const cleanHost = host.replace(/^https?:\/\//, ''); return ALLOWED_HEROKU_DOMAINS.some(domain => cleanHost.endsWith(`.${domain}`)) || LOCALHOST_DOMAINS.some(domain => cleanHost.includes(domain)); } } export const vars = new Vars();