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