Skip to content

Commit

Permalink
cleanup console and guard against external calls and API call types r…
Browse files Browse the repository at this point in the history
…equests
  • Loading branch information
thescientist13 committed Oct 10, 2021
1 parent 3d1d55f commit 0418b18
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions packages/cli/src/lifecycles/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,23 @@ function getDevServer(compilation) {
// ETag Support - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
app.use(async (ctx) => {
const body = ctx.response.body;
// console.debug('body', body);

if (Buffer.isBuffer(body)) {
// console.warn(`no body for => ${ctx.url}`);
} else {
const inm = ctx.headers['if-none-match'];
const etagHash = hashString(body);

if (inm && inm === etagHash) {
ctx.status = 304;
ctx.body = null;
ctx.set('Etag', etagHash);
} else if (!inm || inm !== etagHash) {
ctx.set('Etag', etagHash);
const { url } = ctx;

// don't interfere with extrenal requests or API calls
if (path.extname(url) !== '' && url.indexOf('http') !== 0) {
if (Buffer.isBuffer(body)) {
// console.warn(`no body for => ${ctx.url}`);
} else {
const inm = ctx.headers['if-none-match'];
const etagHash = hashString(body);

if (inm && inm === etagHash) {
ctx.status = 304;
ctx.body = null;
ctx.set('Etag', etagHash);
} else if (!inm || inm !== etagHash) {
ctx.set('Etag', etagHash);
}
}
}

Expand Down

0 comments on commit 0418b18

Please sign in to comment.