Skip to content

Commit

Permalink
fix undesired 404 in develoment mode due to undefined default site
Browse files Browse the repository at this point in the history
  • Loading branch information
vilicvane committed Dec 19, 2015
1 parent a28a5d3 commit cbda2ae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,11 @@ export class Router {
let firstPathPart = pathParts[0];

if (
!firstPathPart || (
firstPathPart !== this.defaultSubsite &&
!FS.existsSync(Path.join(this.routesRoot, firstPathPart))
this.defaultSubsite && (
!firstPathPart || (
firstPathPart !== this.defaultSubsite &&
!FS.existsSync(Path.join(this.routesRoot, firstPathPart))
)
)
) {
pathParts.unshift(this.defaultSubsite);
Expand Down Expand Up @@ -571,7 +573,7 @@ ${route.handler.toString()}`);
}

private handleNotFound(req: ExpressRequest, res: ExpressResponse): void {
this.renderErrorPage(req, res, new APIError(APIErrorCode.none, 'Page not Found.', 404));
this.renderErrorPage(req, res, new APIError(APIErrorCode.none, 'Page not Found', 404));
}

private handleServerError(req: ExpressRequest, res: ExpressResponse, error: Error, hasView: boolean): void {
Expand Down
8 changes: 8 additions & 0 deletions src/test/site-single-routes/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Controller, Request, get, post } from '../../';

export default class DefaultController extends Controller {
@get()
world() {
return 'abc';
}
}
14 changes: 14 additions & 0 deletions test/site-single/test-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@
}
}
},
{
"method": "get",
"path": "/hello/world",
"description": "should get 200",
"expected": {
"all": {
"status": 200,
"contentType": "application/json",
"content": {
"data": "abc"
}
}
}
},
{
"method": "get",
"path": "/oops",
Expand Down

0 comments on commit cbda2ae

Please sign in to comment.