Added "helpful 404" support page
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 6642c4c · Browse files · 5 files·+28 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+28 added−10 removed
- tests:+1 added−2 removed
- other:+27 added−8 removed
Provenance
- Commit
897c590- Tree
596905b- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
6642c4c
5 files changed+28 added−10 removed
modified:examples/app.js+1 added
6 unmodified lines78910111213141525 unmodified lines6 unmodified lines use(CommonLogger) use(MethodOverride) use(ContentLength) set('root', dirname(__filename)) enable('helpful 404') enable('show exceptions') enable('cache views')})
25 unmodified linesmodified:lib/express/pages/not-found.js+8 added-6 removed
4 unmodified lines567899101112132 unmodified lines16171819202122232420212223242526272829304 unmodified lines
exports.render = function() { contentType('html') var request = Express.server.request, method = request.method, method = request.method.toLowerCase(), path = request.uri.path return '<html> \n\ <head> \n\ <title>Express -- Not Found</title> \n\2 unmodified lines <body> \n\ <div id="wrapper"> \n\ <h1>Express</h1> \n\ <h2><em>404</em> Not Found</h2> \n\ <ul id="stacktrace"> \n\ ' + method + '(\'' + path + '\', function(){ \n\ // Try this :) \n\ }) \n\ </ul> \n\ <p>No routes were matched, try the route below.\n\ For restful services ensure that you use(MethodOverride).</p> \n\ <pre><code> \n\ ' + method + '(\'' + path + '\', function(){ \n\ // Response logic \n\ }) \n\ </code></pre> \n\ </div> \n\ </body> \n\ </html>'}No newline at end of fileNo newline at end of filemodified:lib/express/pages/style.js+12 added-1 removed
21 unmodified lines2223242526262728293012 unmodified lines434445464748495051525354555657585921 unmodified lines font-size: 60px; \n\ } \n\ #wrapper { \n\ margin: 50px auto; \n\ width: 600px; \n\ width: 500px; \n\ text-align: left; \n\ } \n\ ul { \n\ margin: 0; \n\12 unmodified lines } \n\ ul li:first-child .path { \n\ padding-left: 0; \n\ } \n\ p { \n\ line-height: 1.5; \n\ } \n\ pre { \n\ margin: 0; \n\ padding: 10px; \n\ border: 1px solid #eee; \n\ -webkit-border-radius: 10px; \n\ -moz-border-radius: 10px; \n\ -webkit-box-shadow: 1px 1px 6px #ddd; \n\ } \n\ </style> \n\ 'No newline at end of fileNo newline at end of filemodified:lib/express/core.js+6 added-1 removed
133 unmodified lines134 135 route: function(request){136 this.request = request137 var route = this.matchingRoute()138- return route ? route.run(this.captures.slice(1)) : halt()138+ if (route)139+ return route.run(this.captures.slice(1))140+ else if (accepts('html') && set('helpful 404'))141+ halt(404, require('express/pages/not-found').render())142+ else143+ halt()144 },145 146 /**147 * Attempt to match a route from Express.routes.163 unmodified linesmodified:spec/spec.routing.js+1 added-2 removed
170 unmodified lines171 describe 'with an unmatchable request path'172 describe 'with "helpful 404" enabled'173 it 'should show the help html'174 enable('helpful 404')175- get('/something').status.should.eql 500175+ get('/something').status.should.eql 404176 get('/something').body.should.include('<h1>Express</h1>')177 get('/something').body.should.include('<h2><em>404</em> Not Found</h2>')178- get('/something').body.should.include("get('/something'")178 end179 end180 181 describe 'with "helpful 404" disabled'54 unmodified lines