{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback-next/issues/1785","repository_url":"https://api.github.com/repos/strongloop/loopback-next","labels_url":"https://api.github.com/repos/strongloop/loopback-next/issues/1785/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback-next/issues/1785/comments","events_url":"https://api.github.com/repos/strongloop/loopback-next/issues/1785/events","html_url":"https://github.com/strongloop/loopback-next/issues/1785","id":365335154,"node_id":"MDU6SXNzdWUzNjUzMzUxNTQ=","number":1785,"title":"Invoke serve-static after API router","user":{"login":"bajtos","id":1140553,"node_id":"MDQ6VXNlcjExNDA1NTM=","avatar_url":"https://avatars1.githubusercontent.com/u/1140553?v=4","gravatar_id":"","url":"https://api.github.com/users/bajtos","html_url":"https://github.com/bajtos","followers_url":"https://api.github.com/users/bajtos/followers","following_url":"https://api.github.com/users/bajtos/following{/other_user}","gists_url":"https://api.github.com/users/bajtos/gists{/gist_id}","starred_url":"https://api.github.com/users/bajtos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bajtos/subscriptions","organizations_url":"https://api.github.com/users/bajtos/orgs","repos_url":"https://api.github.com/users/bajtos/repos","events_url":"https://api.github.com/users/bajtos/events{/privacy}","received_events_url":"https://api.github.com/users/bajtos/received_events","type":"User","site_admin":false},"labels":[{"id":751462267,"node_id":"MDU6TGFiZWw3NTE0NjIyNjc=","url":"https://api.github.com/repos/strongloop/loopback-next/labels/API%20Explorer","name":"API Explorer","color":"fcc53a","default":false},{"id":817780663,"node_id":"MDU6TGFiZWw4MTc3ODA2NjM=","url":"https://api.github.com/repos/strongloop/loopback-next/labels/REST","name":"REST","color":"fcc53a","default":false},{"id":1061281764,"node_id":"MDU6TGFiZWwxMDYxMjgxNzY0","url":"https://api.github.com/repos/strongloop/loopback-next/labels/TOB","name":"TOB","color":"7e02cc","default":false},{"id":534463431,"node_id":"MDU6TGFiZWw1MzQ0NjM0MzE=","url":"https://api.github.com/repos/strongloop/loopback-next/labels/feature","name":"feature","color":"c2e0c6","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-01T07:16:11Z","updated_at":"2018-10-01T07:18:19Z","closed_at":null,"author_association":"MEMBER","body":"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:\r\n - All serve-static middleware is mounted before API routes, violating the best practices.\r\n - Users are forbidden to mount static content at root `/` to avoid the biggest performance penalty.\r\n\r\nLet's rethink the way how static files are served, follow the best practices and get the best performance.\r\n\r\n## Acceptance criteria\r\n\r\n- [ ] `serve-static` middleware is invoked only after no other route (an API endpoint, an Express-like route) matched the request\r\n- [ ] applications can mount static files at root `/`\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback-next/issues/comments/425811120","html_url":"https://github.com/strongloop/loopback-next/issues/1785#issuecomment-425811120","issue_url":"https://api.github.com/repos/strongloop/loopback-next/issues/1785","id":425811120,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNTgxMTEyMA==","user":{"login":"bajtos","id":1140553,"node_id":"MDQ6VXNlcjExNDA1NTM=","avatar_url":"https://avatars1.githubusercontent.com/u/1140553?v=4","gravatar_id":"","url":"https://api.github.com/users/bajtos","html_url":"https://github.com/bajtos","followers_url":"https://api.github.com/users/bajtos/followers","following_url":"https://api.github.com/users/bajtos/following{/other_user}","gists_url":"https://api.github.com/users/bajtos/gists{/gist_id}","starred_url":"https://api.github.com/users/bajtos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bajtos/subscriptions","organizations_url":"https://api.github.com/users/bajtos/orgs","repos_url":"https://api.github.com/users/bajtos/repos","events_url":"https://api.github.com/users/bajtos/events{/privacy}","received_events_url":"https://api.github.com/users/bajtos/received_events","type":"User","site_admin":false},"created_at":"2018-10-01T07:18:19Z","updated_at":"2018-10-01T07:18:19Z","author_association":"MEMBER","body":"In https://github.com/strongloop/loopback-next/pull/1611#issuecomment-415677600 and https://github.com/strongloop/loopback-next/issues/1784, I proposed the following solution for consideration:\r\n\r\nCan we define a special kind of a catch-all route that will:\r\n - 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\r\n - run the express Router where static assets were mounted; i.e. the sequence action `invoke` runs express routing to handle static assets\r\n - 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()`.\r\n\r\nIn my mind, such solution would solve most if not all issues:\r\n - static middleware is invoked after any routes\r\n - static middleware is invoked as part of the sequence\r\n - 404 errors are still handled by the sequence\r\n"}}
{"actor":{"display_login":"bajtos"}}