Skip to content

Commit c9c6bc5

Browse files
committed
fix(cli): allow to set url to the spec in SSR mode
1 parent b116796 commit c9c6bc5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cli/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Options = {
2121
output?: string;
2222
title?: string;
2323
templateFileName?: string;
24-
redocOptions?: object;
24+
redocOptions?: any;
2525
};
2626

2727
const BUNDLES_DIR = dirname(require.resolve('redoc'));
@@ -200,7 +200,9 @@ async function getPageHTML(
200200
let redocStandaloneSrc;
201201
if (ssr) {
202202
console.log('Prerendering docs');
203-
const store = await createStore(spec, pathToSpec, redocOptions);
203+
204+
const specUrl = redocOptions.specUrl || (isURL(pathToSpec) ? pathToSpec : undefined);
205+
const store = await createStore(spec, specUrl, redocOptions);
204206
const sheet = new ServerStyleSheet();
205207
html = renderToString(sheet.collectStyles(React.createElement(Redoc, { store })));
206208
css = sheet.getStyleTags();
@@ -282,3 +284,7 @@ function debounce(callback: Function, time: number) {
282284
}, time);
283285
};
284286
}
287+
288+
function isURL(str: string): boolean {
289+
return /^(https?:)\/\//m.test(str);
290+
}

0 commit comments

Comments
 (0)