Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' into tutorial

  • Loading branch information...
commit c084efc756e1b1d2e47063bb6dd00e0d61e9c4f0 2 parents baea294 + 3dca884
@MiguelMadero authored
Showing with 22 additions and 6 deletions.
  1. +22 −6 lib/app.js
View
28 lib/app.js
@@ -309,10 +309,12 @@ var App = function () {
, accessTime = (new Date()).getTime()
, inFlighId;
+ reqUrl = req.url;
// Sanitize URL; reduce multiple slashes to single slash
- // TODO: Handle trailing slashes correctly, whatever
- // 'correctly' means
- reqUrl = req.url.replace(/\/{2,}/g, '/');
+ reqUrl = reqUrl.replace(/\/{2,}/g, '/');
+ // Strip trailing slash for the purpose of looking for a matching
+ // route (will still check for directory + index on statics)
+ reqUrl = reqUrl.replace(/\/$/, '');
// Buffered request-obj -- buffer the request data,
// and pass this proxy object to the controller
@@ -537,9 +539,23 @@ var App = function () {
// Decode path (e.g. %20)
staticPath = decodeURIComponent(staticPath);
- if ( utils.file.existsSync(staticPath) && fs.statSync(staticPath).isFile() ) {
- staticResp = new response.Response(resp);
- staticResp.sendFile(staticPath);
+ if (utils.file.existsSync(staticPath)) {
+ // May be a path to a directory, with or without a trailing
+ // slash -- any trailing slash has already been stripped by
+ // this point
+ if (fs.statSync(staticPath).isDirectory()) {
+ // TODO: Make the name of any index file configurable
+ staticPath = path.join(staticPath, 'index.html');
+ if (utils.file.existsSync(staticPath) && fs.statSync(staticPath).isFile()) {
+ staticResp = new response.Response(resp);
+ staticResp.sendFile(staticPath);
+ }
+ }
+ // Path to an actual file. Just serve it up
+ else if (fs.statSync(staticPath).isFile()) {
+ staticResp = new response.Response(resp);
+ staticResp.sendFile(staticPath);
+ }
}
else {
// 405?
Please sign in to comment.
Something went wrong with that request. Please try again.