Skip to content

Commit

Permalink
chore: fix redoc standalone path in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Mar 18, 2018
1 parent 4510311 commit f993e9b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -20,6 +20,8 @@ type Options = {
output?: string;
};

const BUNDLES_DIR = dirname(require.resolve('redoc'));

yargs
.command(
'serve [spec]',
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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'));
}
}

Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit f993e9b

Please sign in to comment.