Skip to content

Haul server crashes when navigating to root url #767

Open

Description

@michens

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions