chore: fix redoc standalone path in CLI

This commit is contained in:
Roman Hotsiy 2018-03-18 17:39:50 +02:00
parent 4510311096
commit f993e9b443
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 13 additions and 6 deletions

View File

@ -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'));
}
}

View File

@ -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": {