Skip to content
Browse files

Serving .html files when there's no .html in the URL.

  • Loading branch information...
1 parent 2b5c987 commit ec4a1f4829c3ed63dfe49af0e5f8e736866e2152 @augustl augustl committed Jan 23, 2012
Showing with 12 additions and 9 deletions.
  1. +12 −9 bin/server
View
21 bin/server
@@ -43,23 +43,26 @@ http.createServer(function (req, res) {
var pubFilePath = path.join(PUBLIC, u.pathname);
fs.stat(pubFilePath, function (err, stat) {
if (err || !stat.isFile()) {
- var templatePath = path.join(SITE, u.pathname);
- fs.stat(templatePath, function (err, stat) {
- if (err) {
- notFound(res);
- } else if (stat.isDirectory()) {
- var indexHtmlPath = path.join(templatePath, "index.html");
+ var dirPath = path.join(SITE, u.pathname);
+ fs.stat(dirPath, function (err, stat) {
+ if (!err && stat.isDirectory()) {
+ var indexHtmlPath = path.join(dirPath, "index.html");
fs.stat(indexHtmlPath, function (err, stat) {
if (err || !stat.isFile()) {
notFound(res);
} else {
serveTemplate(indexHtmlPath, res);
}
});
- } else if (stat.isFile()) {
- serveTemplate(templatePath, res);
} else {
- notFound(res);
+ var templatePath = dirPath + ".html";
+ fs.stat(templatePath, function (err, stat) {
+ if (!err && stat.isFile()) {
+ serveTemplate(templatePath, res);
+ } else {
+ notFound(res);
+ }
+ });
}
});
} else {

0 comments on commit ec4a1f4

Please sign in to comment.
Something went wrong with that request. Please try again.