Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haul server crashes when navigating to root url #767

Open
michens opened this issue Oct 21, 2021 · 0 comments
Open

Haul server crashes when navigating to root url #767

michens opened this issue Oct 21, 2021 · 0 comments

Comments

@michens
Copy link

michens commented Oct 21, 2021

Environment

I am on Windows and node v14.15.1, but it looks like this should apply everywhere

Description

When you run haul, you get the following message: done ▶︎ Packager server running on http://localhost:8081
You can click on the link from the console, which opens localhost at the root
This causes haul to crash

I see three places to change that would each mitigate this

  1. Lowest level
callback({
  errors: null,
  platform,
  file: fs.readFileSync(filePath),
  mimeType,
});

file: fs.readFileSync(filePath),

There needs to be error handling when reading a file. A simple try/catch that invokes callback with any errors would suffice

  1. Intermediate level
if (fs.existsSync(filePath)) {
  send(Events.FILE_RECEIVED, {
    taskId: payload.taskId,
    filePath,
    mimeType: mime.lookup(payload.filename) || 'text/javascript',
  });
} else {
  send(Events.FILE_NOT_FOUND, {
    taskId: payload.taskId,
  });
}

existsSync returns true for directories, but there is no reason to send a directory path to the compiler. A check to ensure that the path is a file (e.g. with a call to statSync) would prevent this issue

  1. Highest level
server.route({
    method: 'GET',
    path: '/{any*}',
    ...
})

This sends every unknown path to the compiler, which is not desirable for the root

Adding a simple redirect like the following to setupDevtoolRoutes.ts would catch this and help developers get to their expected destination

server.route({
  method: 'GET',
  path: '/',
  handler: (_, h) => h.redirect('/debugger-ui')
});

Reproducible Demo

This applies to every haul project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant