-
Notifications
You must be signed in to change notification settings - Fork 190
Description
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
- 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
- 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,
});
}| if (fs.existsSync(filePath)) { |
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
- Highest level
server.route({
method: 'GET',
path: '/{any*}',
...
})| 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