esbuild-server
esbuild-server copied to clipboard
Not compatible with single page applications?
I have tried using this plugin in a react app. It works fine when I land at localhost:3000
. Routing to something like localhost:3000/dashboard
also works fine. But in the routed path if I refresh the page, it just sends, "Not found". I have found the code where it happens.
// https://github.com/oblador/esbuild-server/blob/master/src/index.ts
// Attempt to serve file from build or static directory
for (const dir of staticDirs) {
const staticFilePath = path_1.default.normalize(path_1.default.join(dir, url.pathname === '/' ? 'index.html' : url.pathname));
console.log(url.pathname, staticFilePath)
if (staticFilePath.startsWith(dir)) {
try {
return await sendFile(res, staticFilePath);
}
catch (err) {
if (err.code !== 'ENOENT' && err.code !== 'EISDIR') {
throw err;
}
}
}
}
It seems it is checking if a directory with the same name as the route path is available or not. If not found it returns "Not found". But in case of SPAs there will be no directory as the route name.