histoire
Version:
A fast story book powered by Vite
21 lines (20 loc) • 844 B
JavaScript
import { createStoryUrl, StoryRouteError } from '@histoire/cli/workbench-url';
import { getSandboxRelativeUrl } from '@histoire/shared';
import { McpDomainError } from '../protocol/errors.js';
/** Return UI and sandbox addresses without credentials or browser readiness claims. */
export function createPreviewUrls(options) {
const origin = new URL(options.origin);
let storyUrl;
try {
storyUrl = createStoryUrl(options);
}
catch (error) {
if (!(error instanceof StoryRouteError))
throw error;
throw new McpDomainError('PREVIEW_NOT_READY', error.reason === 'origin' ? 'Preview origin is unavailable' : 'Preview base must be a same-origin absolute path', true);
}
return {
storyUrl,
sandboxUrl: new URL(getSandboxRelativeUrl(options), origin.origin).href,
};
}