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

Not compatible with single page applications? #13

Closed
roymrinmoy opened this issue Oct 19, 2023 · 1 comment
Closed

Not compatible with single page applications? #13

roymrinmoy opened this issue Oct 19, 2023 · 1 comment

Comments

@roymrinmoy
Copy link

roymrinmoy commented Oct 19, 2023

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.

@oblador
Copy link
Owner

oblador commented Aug 19, 2024

Pass historyApiFallback: true in options as per the README.

@oblador oblador closed this as completed Aug 19, 2024
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

2 participants