Permalink
Browse files

made file and view cache available in each request

  • Loading branch information...
1 parent a5d2133 commit 2d4f3574ef4d8ceaa003c77ed8a92cf736ae6040 Tim Schindler committed Apr 28, 2012
Showing with 33 additions and 12 deletions.
  1. +5 −0 bin/create-app.sh
  2. +11 −0 lib/file.js
  3. +13 −10 lib/server.js
  4. +3 −1 lib/view.js
  5. +1 −1 package.json
View
5 bin/create-app.sh
@@ -8,6 +8,11 @@ mkdir -p ./public
mkdir -p ./public/image
mkdir -p ./public/stylesheet
mkdir -p ./public/javascript
+mkdir -p ./public/javascript/controller
+mkdir -p ./public/javascript/model
+mkdir -p ./public/javascript/view
+mkdir -p ./public/javascript/plugin
+mkdir -p ./public/javascript/vendor
mkdir -p ./test
View
11 lib/file.js
@@ -59,6 +59,17 @@ var file = {
});
});
});
+ },
+
+ /*
+ *
+ */
+ init: function(req, res, cb) {
+ res.file = {
+ cache: this.cache
+ };
+
+ cb();
}
};
View
23 lib/server.js
@@ -20,14 +20,14 @@ var url = require('url')
* Server module. A request controller for node http server.
*/
var server = {
- /*
- * Handle the request of the http server instance.
- *
- * @param app, object containing all application routes.
- * @param req, object of a server request.
- * @param res, object of a server response.
- */
- requestHandler: function serverRequestHandler(app, req, res) {
+ /*
+ * Handle the request of the http server instance.
+ *
+ * @param app, object containing all application routes.
+ * @param req, object of a server request.
+ * @param res, object of a server response.
+ */
+ requestHandler: function serverRequestHandler(app, req, res) {
var url = req.url.pathname
, reqFile = config.fileTypes[file.ext(url)];
@@ -37,7 +37,7 @@ var server = {
return res.end(file.cache[url], reqFile.encoding);
}
- var modules = ['session', 'cookie', 'view'];
+ var modules = ['session', 'cookie', 'view', 'file'];
var callbackQueue = CallbackQueue(modules, function() {
// Render requested view if it exists.
var requestedView = app[res.session.authType][req.method][url];
@@ -61,12 +61,15 @@ var server = {
cookie.init(req, res, function() {
callbackQueue.register('cookie');
-
});
view.init(req, res, function() {
callbackQueue.register('view');
});
+
+ file.init(req, res, function() {
+ callbackQueue.register('file');
+ });
},
/*
View
4 lib/view.js
@@ -108,7 +108,9 @@ var view = {
*
*/
init: function init(req, res, cb) {
- res.view = {};
+ res.view = {
+ cache: this.cache
+ };
res.view.redirect = function redirect(url) {
res.writeHead(301, {'Location': url});
View
2 package.json
@@ -2,7 +2,7 @@
"name": "sayndo",
"author": "Tim Schindler <tim.schindler@adcloud.com>",
"description": "Fast and flexible web server with customized routing and authorization.",
- "version": "0.0.6",
+ "version": "0.0.7",
"repository": {
"type": "git",
"url": "git://github.com/zyndiecate/sayndo.git"

0 comments on commit 2d4f357

Please sign in to comment.