mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-25 10:03:45 +03:00
fix(cli): allow to set url to the spec in SSR mode
This commit is contained in:
parent
b11679604a
commit
c9c6bc5255
10
cli/index.ts
10
cli/index.ts
|
@ -21,7 +21,7 @@ type Options = {
|
||||||
output?: string;
|
output?: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
templateFileName?: string;
|
templateFileName?: string;
|
||||||
redocOptions?: object;
|
redocOptions?: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
const BUNDLES_DIR = dirname(require.resolve('redoc'));
|
const BUNDLES_DIR = dirname(require.resolve('redoc'));
|
||||||
|
@ -200,7 +200,9 @@ async function getPageHTML(
|
||||||
let redocStandaloneSrc;
|
let redocStandaloneSrc;
|
||||||
if (ssr) {
|
if (ssr) {
|
||||||
console.log('Prerendering docs');
|
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();
|
const sheet = new ServerStyleSheet();
|
||||||
html = renderToString(sheet.collectStyles(React.createElement(Redoc, { store })));
|
html = renderToString(sheet.collectStyles(React.createElement(Redoc, { store })));
|
||||||
css = sheet.getStyleTags();
|
css = sheet.getStyleTags();
|
||||||
|
@ -282,3 +284,7 @@ function debounce(callback: Function, time: number) {
|
||||||
}, time);
|
}, time);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isURL(str: string): boolean {
|
||||||
|
return /^(https?:)\/\//m.test(str);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user