Skip to content

Commit

Permalink
add requestHandler fall-through - closes #1295 (#1297)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored Oct 13, 2020
1 parent 5074799 commit aa06d5d
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ export async function startServer(commandOptions: CommandOptions) {
}
}

async function requestHandler(req: http.IncomingMessage, res: http.ServerResponse) {
async function requestHandler(req: http.IncomingMessage, res: http.ServerResponse, next?: () => void) {
const reqUrl = req.url!;
const reqUrlHmrParam = reqUrl.includes('?mtime=') && reqUrl.split('?')[1];
let reqPath = decodeURI(url.parse(reqUrl).pathname!);
Expand Down Expand Up @@ -504,14 +504,19 @@ export async function startServer(commandOptions: CommandOptions) {
}

if (!fileLoc) {
// Don't log favicon "Not Found" errors. Browsers automatically request a favicon.ico file
// from the server, which creates annoying errors for new apps / first experiences.
if (reqPath !== '/favicon.ico') {
const attemptedFilesMessage = attemptedFileLoads.map((loc) => ' ✘ ' + loc).join('\n');
const errorMessage = `[404] ${reqUrl}\n${attemptedFilesMessage}`;
logger.error(errorMessage);
if (next) {
// fall through to next handler
return next();
} else {
// Don't log favicon "Not Found" errors. Browsers automatically request a favicon.ico file
// from the server, which creates annoying errors for new apps / first experiences.
if (reqPath !== '/favicon.ico') {
const attemptedFilesMessage = attemptedFileLoads.map((loc) => ' ✘ ' + loc).join('\n');
const errorMessage = `[404] ${reqUrl}\n${attemptedFilesMessage}`;
logger.error(errorMessage);
}
return sendError(req, res, 404);
}
return sendError(req, res, 404);
}

/**
Expand Down

1 comment on commit aa06d5d

@vercel
Copy link

@vercel vercel bot commented on aa06d5d Oct 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.