mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 16:46:34 +03:00
chore: fix redoc standalone path in CLI
This commit is contained in:
parent
4510311096
commit
f993e9b443
17
cli/index.ts
17
cli/index.ts
|
@ -4,7 +4,7 @@ import { renderToString } from 'react-dom/server';
|
|||
import { ServerStyleSheet } from 'styled-components';
|
||||
import { createServer, ServerResponse, ServerRequest } from 'http';
|
||||
import * as zlib from 'zlib';
|
||||
import { resolve } from 'path';
|
||||
import { join, dirname } from 'path';
|
||||
|
||||
// @ts-ignore
|
||||
import { Redoc, loadAndBundleSpec, createStore } from 'redoc';
|
||||
|
@ -20,6 +20,8 @@ type Options = {
|
|||
output?: string;
|
||||
};
|
||||
|
||||
const BUNDLES_DIR = dirname(require.resolve('redoc'));
|
||||
|
||||
yargs
|
||||
.command(
|
||||
'serve [spec]',
|
||||
|
@ -98,9 +100,14 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) {
|
|||
const server = createServer((request, response) => {
|
||||
console.time('GET ' + request.url);
|
||||
if (request.url === '/redoc.standalone.js') {
|
||||
respondWithGzip(createReadStream('bundles/redoc.standalone.js', 'utf8'), request, response, {
|
||||
'Content-Type': 'application/javascript',
|
||||
});
|
||||
respondWithGzip(
|
||||
createReadStream(join(BUNDLES_DIR, 'redoc.standalone.js'), 'utf8'),
|
||||
request,
|
||||
response,
|
||||
{
|
||||
'Content-Type': 'application/javascript',
|
||||
},
|
||||
);
|
||||
} else if (request.url === '/') {
|
||||
respondWithGzip(pageHTML, request, response);
|
||||
} else if (request.url === '/spec.json') {
|
||||
|
@ -166,7 +173,7 @@ async function getPageHTML(spec: any, pathToSpec: string, { ssr, cdn }: Options)
|
|||
state = await store.toJS();
|
||||
|
||||
if (!cdn) {
|
||||
redocStandaloneSrc = readFileSync(resolve(__dirname, '../bundles/redoc.standalone.js'));
|
||||
redocStandaloneSrc = readFileSync(join(BUNDLES_DIR, 'redoc.standalone.js'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "redoc-cli",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.0",
|
||||
"description": "ReDoc's Command Line Interface",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
|
|
Loading…
Reference in New Issue
Block a user