fix(cli): allow to set url to the spec in SSR mode

This commit is contained in:
Roman Hotsiy 2018-03-20 13:22:41 +02:00
parent b11679604a
commit c9c6bc5255
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0

View File

@ -21,7 +21,7 @@ type Options = {
output?: string;
title?: string;
templateFileName?: string;
redocOptions?: object;
redocOptions?: any;
};
const BUNDLES_DIR = dirname(require.resolve('redoc'));
@ -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();
@ -282,3 +284,7 @@ function debounce(callback: Function, time: number) {
}, time);
};
}
function isURL(str: string): boolean {
return /^(https?:)\/\//m.test(str);
}