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

How to handle the single page web application? #140

Open
zhengxiaoyao0716 opened this issue Mar 4, 2019 · 0 comments
Open

How to handle the single page web application? #140

zhengxiaoyao0716 opened this issue Mar 4, 2019 · 0 comments

Comments

@zhengxiaoyao0716
Copy link

zhengxiaoyao0716 commented Mar 4, 2019

Such as in react, we often pack all the routes into one html bundle. I expected to handle all the request route and redirected them to the index.html, is there some way to do it elegant?

As for now, I used those code to do it, but it not perfect way, for example, request for JSON files maybe also redirected unexpectly:

app.serveFolder(path.join(buildDir, 'static'), 'static');
app.serveHandler(async request => {
    if (request.resourceType() !== 'Document') {
      request.continue();
      return;
    }
    const headers = { 'content-type': 'text/html' };
    const body = await fsReadFile(path.join(buildDir, 'index.html'));
    request.fulfill({ headers, body });
  });
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