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

Conversation

@dotch
Copy link
Contributor

@dotch dotch commented Apr 2, 2015

fixes #501

@ilanbiala
Copy link
Member

So what routes have been modified now?

@dotch
Copy link
Contributor Author

dotch commented Apr 5, 2015

Sorry for the lacking explanation.

The server is responsible for the following routes:
/api/*
/components/*
/lib/*
/server-error
The other routes (/*) are handled by Angular due to html5mode.

This PR shows the server 404 page for:
/api/*
/components/*
/lib/*
when no route-handler kicks in due a non existing endpoint, component or library.

Angular route handling is not part of this PR.

@simison
Copy link
Contributor

simison commented May 15, 2015

BTW, would be great if non existing API routes would return 404 as a JSON.

Something like this http://stackoverflow.com/a/9802006

@lirantal lirantal self-assigned this May 15, 2015
@lirantal
Copy link
Member

sounds like a good enhancement indeed, need to take a look at that further

@simison
Copy link
Contributor

simison commented May 16, 2015

@lirantal are you gonna look into 404 stuff for 0.4.0? (har har those digits). If not, I'm also fiddling with this stuff now, but I'm sure you have more perspective.

This still requires 404 handling at Angular side, now app just redirects to / (often confusing users). Redirecting to /not-found is kinda fine, but would be better not to change URL at the URL-bar. location:false option at $state.go() could be useful for that.

Would be lovely to get real 404 headers working for /* stuff as well from Express (instead of giving the job for Angular), but that would require shared configs for URL routing between Express and Angular. Not sure how feasible is that...

@lirantal
Copy link
Member

@simison go ahead and look at it, it's ok with me.

@lirantal lirantal removed their assignment May 16, 2015
simison added a commit to simison/mean that referenced this pull request 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
@simison
Copy link
Contributor

simison commented May 18, 2015

@lirantal See #566

@lirantal lirantal merged commit 74273da into meanjs:0.4.0 Jul 20, 2015
kgrossnickle pushed a commit to cen3031-5a/trainerScheduling that referenced this pull request Oct 10, 2017
- `/{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/mean#503

And `req.accepts()` idea came from http://stackoverflow.com/a/9802006
jspyhotdev pushed a commit to jspyhotdev/MEAN-board that referenced this pull request Aug 14, 2018
- `/{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/mean#503

And `req.accepts()` idea came from http://stackoverflow.com/a/9802006
lupinthethirdgentleman pushed a commit to lupinthethirdgentleman/mean-dashboard that referenced this pull request Aug 5, 2021
- `/{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/mean#503

And `req.accepts()` idea came from http://stackoverflow.com/a/9802006
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants