From 2864512018d3d1c28b76fa34898c4acf607a10bb Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 25 Nov 2013 14:53:16 +0000 Subject: [PATCH] feature(server) combine: add minify --- lib/server.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/server.js b/lib/server.js index 8b490c42..2f6a9d66 100644 --- a/lib/server.js +++ b/lib/server.js @@ -170,7 +170,7 @@ lRet = Util.exec(Route, lData); if (!lRet) - lRet = combine(lPath, pRes); + lRet = combine(lData); if (!lRet) { lName = lData.name; @@ -204,19 +204,37 @@ } } - function combine(path, res) { - var names, + function combine(params) { + var names, i, n, name, minName, + config = main.config, dir = DIR, - COMBINE = '/combine', + p = params, + path = params.name, + COMBINE = '/combine/', isCombine = Util.isContainStrAtBegin(path, COMBINE); if (isCombine) { path = Util.removeStrOneTime(path, COMBINE); names = path.split(':'); - console.log(names, DIR); - files.readPipe(names, dir, res, function(error) { - Util.log(error); - main.sendError(res); + n = names.length; + + if (config.minify) + for (i = 0; i < n; i++) { + name = Path.join(DIR, names[i]); + minName = Minify.getName(name); + if (name !== minName) { + names[i] = minName; + dir = ''; + } + } + + console.log(names); + + files.readPipe(names, dir, p.response, function(error) { + if (error) { + Util.log(error); + main.sendError(params, error); + } }); }