Skip to content

Commit

Permalink
Merge pull request #9 from NodeLab/feature/addTemplate
Browse files Browse the repository at this point in the history
fix: repair deep url
  • Loading branch information
elrrrrrrr committed May 13, 2015
2 parents 61f8b66 + 9b994ca commit 0f1e833
Show file tree
Hide file tree
Showing 15 changed files with 4,339 additions and 8 deletions.
5 changes: 4 additions & 1 deletion lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var chokidar = require('chokidar');
var io = require('./socket');
var path = require('path');
var clc = require('cli-color');
var cwd = process.cwd();
chokidar.watch(path.join(process.cwd()))
.on('change', function(path) {
if (isType(path, 'ftl')) {
Expand All @@ -16,7 +17,9 @@ chokidar.watch(path.join(process.cwd()))
if( isType(path, 'js')) {
io.emit('reloadAll');
}
console.log(clc.blackBright(path) + ': ' + clc.green('changed'));
console.log(
clc.bgMagenta('|watch|'),
clc.blackBright('["' + path.replace(cwd + '/', '') + '"]') + ' ' + clc.green('changed'));
});

function isType(path, type) {
Expand Down
16 changes: 9 additions & 7 deletions routes/reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ var types = [
];
router.get('*', function(req, res, next) {
var file;
if (req.url == '/') {
var _fi = existIndex();
if (req.url.slice(-1) == '/') {
var _fi = existIndex(req.url);
_fi ? file = _fi : next();
} else {
var _ft = existType(req.url);
_ft ? file = _ft : next();
_ft ? file = _ft : next();
}
if (file) {
sendRenderHtml(path.join(cwd, file), res);
sendRenderHtml(file, res);
}

});
Expand All @@ -39,10 +39,11 @@ function sendRenderHtml(file, res) {
});
}

function existIndex() {
function existIndex(url) {
for (var i = 0, len = types.length; i < len; i ++) {
if (fs.existsSync(path.join(cwd, 'index' + types[i]))) {
return 'index' + types[i];
url = path.join(cwd, url,'index' + types[i]);
if (fs.existsSync(url)) {
return url;
}
return false;
}
Expand All @@ -51,6 +52,7 @@ function existIndex() {
function existType(url) {
for (var i = 0, len = types.length; i < len; i ++ ) {
if (url.indexOf(types[i]) > -1) {
url = path.join(cwd, url);
return url;
}
}
Expand Down
Loading

0 comments on commit 0f1e833

Please sign in to comment.