Skip to content

Commit

Permalink
fix: preview server hot reload
Browse files Browse the repository at this point in the history
Signed-off-by: BohdanPetryshyn <b.y.petryshyn@gmail.com>
  • Loading branch information
BohdanPetryshyn committed May 6, 2022
1 parent f973e1c commit 69627f9
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,24 @@ export default async function startPreviewServer(
});
}
} else {
const filePath =
let filePath =
// @ts-ignore
{
'/hot.js': path.join(__dirname, 'hot.js'),
'/oauth2-redirect.html': path.join(__dirname, 'oauth2-redirect.html'),
'/simplewebsocket.min.js': require.resolve('simple-websocket/simplewebsocket.min.js'),
}[request.url || ''] ||
path.resolve(htmlTemplate ? path.dirname(htmlTemplate) : process.cwd(), `.${request.url}`);
}[request.url || ''];

if (!isSubdir(process.cwd(), filePath)) {
respondWithGzip('404 Not Found', request, response, { 'Content-Type': 'text/html' }, 404);
console.timeEnd(colorette.dim(`GET ${request.url}`));
return;
if (!filePath) {
const basePath = htmlTemplate ? path.dirname(htmlTemplate) : process.cwd();

filePath = path.resolve(basePath, `.${request.url}`);

if (!isSubdir(basePath, filePath)) {
respondWithGzip('404 Not Found', request, response, { 'Content-Type': 'text/html' }, 404);
console.timeEnd(colorette.dim(`GET ${request.url}`));
return;
}
}

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

0 comments on commit 69627f9

Please sign in to comment.