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

Invoke serve-static after API router #1785

Closed
2 tasks
bajtos opened this issue Oct 1, 2018 · 2 comments
Closed
2 tasks

Invoke serve-static after API router #1785

bajtos opened this issue Oct 1, 2018 · 2 comments
Assignees
Labels
API Explorer feature REST Issues related to @loopback/rest package and REST transport in general

Comments

@bajtos
Copy link
Member

bajtos commented Oct 1, 2018

In #1611, we added API allowing app developers to serve static assets from their applications. To merge the pull request sooner, we have intentionally accepted a design with suboptimal performance:

  • All serve-static middleware is mounted before API routes, violating the best practices.
  • Users are forbidden to mount static content at root / to avoid the biggest performance penalty.

Let's rethink the way how static files are served, follow the best practices and get the best performance.

See also #559

Acceptance criteria

  • serve-static middleware is invoked only after no other route (an API endpoint, an Express-like route) matched the request
  • applications can mount static files at root /
@bajtos bajtos added feature API Explorer REST Issues related to @loopback/rest package and REST transport in general TOB labels Oct 1, 2018
@bajtos
Copy link
Member Author

bajtos commented Oct 1, 2018

In #1611 (comment) and #1784, I proposed the following solution for consideration:

Can we define a special kind of a catch-all route that will:

  • match any URL that did not match any API endpoint; i.e. the sequence action findRoute returns this catch-all route if no API endpoint matched the requested URL
  • run the express Router where static assets were mounted; i.e. the sequence action invoke runs express routing to handle static assets
  • throw HttpError.NotFound when no static asset was found, i.e. the sequence action invoke throws the 404 error or the express Router for static assets called next().

In my mind, such solution would solve most if not all issues:

  • static middleware is invoked after any routes
  • static middleware is invoked as part of the sequence
  • 404 errors are still handled by the sequence

@hacksparrow
Copy link
Contributor

Fixed via #1848

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Explorer feature REST Issues related to @loopback/rest package and REST transport in general
Projects
None yet
Development

No branches or pull requests

2 participants