Skip to content

Commit

Permalink
fix(cli): allow to set url to the spec in SSR mode
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Mar 20, 2018
1 parent b116796 commit c9c6bc5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Options = {
output?: string;
title?: string;
templateFileName?: string;
redocOptions?: object;
redocOptions?: any;
};

const BUNDLES_DIR = dirname(require.resolve('redoc'));
Expand Down Expand Up @@ -200,7 +200,9 @@ async function getPageHTML(
let redocStandaloneSrc;
if (ssr) {
console.log('Prerendering docs');
const store = await createStore(spec, pathToSpec, redocOptions);

const specUrl = redocOptions.specUrl || (isURL(pathToSpec) ? pathToSpec : undefined);
const store = await createStore(spec, specUrl, redocOptions);
const sheet = new ServerStyleSheet();
html = renderToString(sheet.collectStyles(React.createElement(Redoc, { store })));
css = sheet.getStyleTags();
Expand Down Expand Up @@ -282,3 +284,7 @@ function debounce(callback: Function, time: number) {
}, time);
};
}

function isURL(str: string): boolean {
return /^(https?:)\/\//m.test(str);
}

0 comments on commit c9c6bc5

Please sign in to comment.