Skip to content

Commit

Permalink
Strip query parameters from request URL in preview server
Browse files Browse the repository at this point in the history
  • Loading branch information
kslat3r committed Aug 26, 2021
1 parent 6f23fb4 commit d97df21
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ export default async function startPreviewServer(
) {
const defaultTemplate = path.join(__dirname, 'default.hbs');
const handler = async (request: IncomingMessage, response: any) => {
console.time(colorette.dim(`GET ${request.url}`));
const url = request.url.split('?')[0];
console.time(colorette.dim(`GET ${url}`));
const { htmlTemplate } = getOptions() || {};

if (request.url === '/') {
if (url === '/') {
respondWithGzip(
getPageHTML(htmlTemplate || defaultTemplate, getOptions(), useRedocPro, wsPort),
request,
Expand All @@ -72,7 +73,7 @@ export default async function startPreviewServer(
'Content-Type': 'text/html',
},
);
} else if (request.url === '/openapi.json') {
} else if (url === '/openapi.json') {
const bundle = await getBundle();
if (bundle === undefined) {
respondWithGzip(
Expand Down Expand Up @@ -101,8 +102,8 @@ export default async function startPreviewServer(
{
'/hot.js': path.join(__dirname, 'hot.js'),
'/simplewebsocket.min.js': require.resolve('simple-websocket/simplewebsocket.min.js'),
}[request.url || ''] ||
path.resolve(htmlTemplate ? path.dirname(htmlTemplate) : process.cwd(), `.${request.url}`);
}[url || ''] ||
path.resolve(htmlTemplate ? path.dirname(htmlTemplate) : process.cwd(), `.${url}`);

const extname = String(path.extname(filePath)).toLowerCase() as keyof typeof mimeTypes;

Expand All @@ -125,7 +126,7 @@ export default async function startPreviewServer(
}
}
}
console.timeEnd(colorette.dim(`GET ${request.url}`));
console.timeEnd(colorette.dim(`GET ${url}`));
};

let wsPort = await portfinder.getPortPromise({ port: 32201 });
Expand Down

0 comments on commit d97df21

Please sign in to comment.