Skip to content

Commit

Permalink
fix: use the baseUrl from the request api call
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-almeida committed Jul 9, 2024
1 parent 6563e10 commit e7e2552
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
8 changes: 1 addition & 7 deletions packages/zcli-themes/src/commands/themes/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as morgan from 'morgan'
import * as chalk from 'chalk'
import * as cors from 'cors'
import * as chokidar from 'chokidar'
import { Auth, getBaseUrl } from '@zendesk/zcli-core'
import preview from '../../lib/preview'
import getManifest from '../../lib/getManifest'
import getVariables from '../../lib/getVariables'
Expand Down Expand Up @@ -56,8 +55,7 @@ export default class Preview extends Command {
}
}

await preview(themePath, flags)

const baseUrl = await preview(themePath, flags)
const app = express()
const server = httpsServerOptions === null ? http.createServer(app) : https.createServer(httpsServerOptions, app)
const wss = new WebSocket.Server({ server, path: '/livereload' })
Expand Down Expand Up @@ -87,10 +85,6 @@ export default class Preview extends Command {
})

server.listen(port, host, async () => {
// preview requires authentication so we're sure
// to have a logged in profile at this point
const { subdomain, domain } = await new Auth().getLoggedInProfile()
const baseUrl = getBaseUrl(subdomain, domain)
this.log(chalk.bold.green('Ready', chalk.blueBright(`${baseUrl}/hc/admin/local_preview/start`, '🚀')))
this.log(`You can exit preview mode in the UI or by visiting ${baseUrl}/hc/admin/local_preview/stop`)
tailLogs && this.log(chalk.bold('Tailing logs'))
Expand Down
5 changes: 3 additions & 2 deletions packages/zcli-themes/src/lib/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import validationErrorsToString from './validationErrorsToString'
import { getLocalServerBaseUrl } from './getLocalServerBaseUrl'
import type { AxiosError } from 'axios'

export default async function preview (themePath: string, flags: Flags): Promise<void> {
export default async function preview (themePath: string, flags: Flags): Promise<string | void> {
const manifest = getManifest(themePath)
const templates = getTemplates(themePath)
const variables = getVariables(themePath, manifest.settings, flags)
Expand All @@ -32,7 +32,7 @@ export default async function preview (themePath: string, flags: Flags): Promise

try {
CliUx.ux.action.start('Uploading theme')
await request.requestAPI('/hc/api/internal/theming/local_preview', {
const { config: { baseURL } } = await request.requestAPI('/hc/api/internal/theming/local_preview', {
method: 'put',
headers: {
'X-Zendesk-Request-Originator': 'zcli themes:preview'
Expand All @@ -56,6 +56,7 @@ export default async function preview (themePath: string, flags: Flags): Promise
validateStatus: (status: number) => status === 200
})
CliUx.ux.action.stop('Ok')
return baseURL
} catch (e) {
CliUx.ux.action.stop(chalk.bold.red('!'))
const { response, message } = e as AxiosError
Expand Down

0 comments on commit e7e2552

Please sign in to comment.