Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Page not found handler not working in 0.4.0 #501

Closed
debrouxl opened this issue Apr 1, 2015 · 4 comments
Closed

Page not found handler not working in 0.4.0 #501

debrouxl opened this issue Apr 1, 2015 · 4 comments

Comments

@debrouxl
Copy link

debrouxl commented Apr 1, 2015

Steps to reproduce:

Expected result:

Actual result:

If I remove the "*" from the last route of modules/core/server/routes/core.server.routes.js, the 404 functionality is restored; however, sign up, sign in and pretty much everything else is broken, because of the fallback to the error routes defined in config/lib/express.js. I haven't yet found what the correct fix is.

I noticed the issue on my own testing application, when the server not only produced a 200 status code, but also the HTML content of the root page, when requested an image which wasn't there.

@dotch
Copy link
Contributor

dotch commented Apr 2, 2015

Since we are using html5-mode routes, angular is responsible for showing 404 pages for most routes, right?
so I guess we should handle the server side 404s like this:

// Return a 404 for all undefined api, module or lib routes
app.route('/:url(api|modules|lib)/*').get(core.renderNotFound); 

and either keep the redirect for everything else or implement angular based 404 logic as well.

simison added a commit to simison/mean that referenced this issue May 18, 2015
simison added a commit to simison/mean that referenced this issue May 18, 2015
- `/{api|modules|lib}/*` returns error page when path doesn’t exist
(from Express).
- `/*` always returns index (from Express), but if `$state` doesn’t
exist, Angular redirects to `/not-found` (no 404 status in that case
though!)
- If `Accept: application/json` header is present without `Accept:
text/html`, return error as json. Hence looking at non existing /api/*
paths with browser would show html error, but querying them with script
would return json.
- Slightly prettier 404 error

Test:
```bash
curl http://localhost:3000/api/notfound -4 -H "Accept: application/json"
```
=> json error.

```bash
curl http://localhost:3000/api/notfound -4 -H "Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0
.8"
```
=> html error (imitates Chrome’s Accept header).

Starting point was @dotch’s PL: meanjs#503

And `req.accepts()` idea came from http://stackoverflow.com/a/9802006
@lirantal lirantal mentioned this issue Jul 20, 2015
14 tasks
lirantal added a commit that referenced this issue Jul 20, 2015
#501 Handle 404 errors at Express backend and at Angular frontend
@lirantal
Copy link
Member

I assume we can close this now that we merged #566 ?

@mleanos
Copy link
Member

mleanos commented Jul 26, 2015

I've verified this is working after merging #566. The app is responding with the not-found route on the front-end, when a non existing route is requested.

@codydaig
Copy link
Member

Verified. Let's close.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants