Permalink
Browse files

Added event for post data

  • Loading branch information...
1 parent b66f9b6 commit 373eaa84ae21aa0be0f961b8476491e7469492b5 @fk1blow committed Jun 1, 2011
Showing with 42 additions and 22 deletions.
  1. +42 −22 lib/Http/HttpDispatcher.js
View
64 lib/Http/HttpDispatcher.js
@@ -1,35 +1,55 @@
var Response = require('./Response'),
Request = require('./Request'),
- ActiveRouter = require('../Router/ActiveRouter'),
- Controllers = require('../Controller/ActionController');
+ ActionDispatcher = require('../Controller/Controller').ActionDispatcher,
+ Config = require('../Config'),
+ File = require('../File/File'),
+ Mimes = require('./Mimes'),
+ url = require('url');
+var StaticRequest = {
+ default_extensions: /\.(js|html|css|swf|jpg|jpeg|png|gif)$/,
+
+ hasAssets: function(req) {
+ var path = url.parse(req.url).pathname;
+ var regexp = this.default_extensions;
+ var is_asset = regexp.test(path);
+
+ if(is_asset) {
+ var matches = path.match(regexp);
+ this.getAsset(Config.getPathFor('public') + path, matches[1]);
+ return true;
+ }
+ return false;
+ },
+
+ getAsset: function(file_path, ctype) {
+ var r = File.readFile(file_path);
+ Response.sendToBody(r, {'Content-type': Mimes[ctype]});
+ }
+}
+
/**
* HttpDispatcher
* @package Http
- *
- * @todo move the router handling outside http package
- * The ActionController should deal with the router objects...
*/
-var HttpDispatcher = Klass({
- statics: {
- handleRequest: function(req, res) {
- this._handleInitializers(req, res);
- this._handleDispatcher(res);
- },
+var HttpDispatcher = {
+ handleRequest: function(req, res) {
+ this._handleInitializers(req, res);
+ },
+
+ _handleInitializers: function(req, res) {
+ // Setting the main Response object
+ Response.setObject(res);
- _handleInitializers: function(req, res) {
- Request.setObject(req);
- Response.setObject(res);
- ActiveRouter.initRouter(req);
- },
-
- _handleDispatcher: function(res) {
- Controllers.dispatch(res);
- }
+ // Builds the request object
+ Request.Build(req, function() {
+ if(!StaticRequest.hasAssets(req)) {
+ ActionDispatcher.dispatch(res);
+ }
+ });
}
-});
+};
module.exports = HttpDispatcher;
-

0 comments on commit 373eaa8

Please sign in to comment.