Permalink
Browse files

Merge branch 'master' into feature/socket.io-mvc

Conflicts:
	lib/app.js
	templates/base/development.js
	templates/base/environment.js
	templates/base/production.js
  • Loading branch information...
2 parents 5e180a3 + 680b9d3 commit 602ecf133a7b8171bb78eec11cef374f30b0e0c4 Techwraith committed Nov 3, 2012
View
@@ -135,6 +135,7 @@ if (cmds.length) {
if (!(cmds[0] == 'jake' ||
cmds[0] == 'secret' ||
cmds[0] == 'db:init' ||
+ cmds[0] == 'auth' ||
cmds[0] == 'console')
&& !cmds[1]) {
throw new Error(cmds[0] + ' command requires another argument.');
@@ -171,6 +172,10 @@ if (cmds.length) {
// Create DBs
cmd += 'console:start[' + (cmds[1] || 'development') + ']';
break;
+ case 'auth':
+ // Create DBs
+ cmd += 'auth:init';
+ break;
case 'db:init':
// Create DBs
cmd += 'db:init';
No changes.
View
@@ -25,14 +25,17 @@ var fs = require('fs')
, cwd = process.cwd()
, errors = require('./response/errors')
, response = require('./response')
- , utils = require('utilities')
, init = require('./init')
, helpers = require('./template/helpers')
, actionHelpers = require('./template/helpers/action')
- , BaseController = require('./base_controller').BaseController
+ , BaseController = require('./controller/base_controller').BaseController
+ , ErrorController = require('./controller/error_controller').ErrorController
+ , StaticFileController =
+ require('./controller/static_file_controller').StaticFileController
, sessions = require('./sessions')
, CookieCollection = require('./cookies').CookieCollection
, Request = require('./request').Request
+ , Response = response.Response
, InFlight = require('./in_flight').InFlight
, i18n = utils.i18n
, usingCoffee; // Global variable for CoffeeScript
@@ -319,6 +322,7 @@ var App = function () {
geddy.server.addListener('request', function (req, resp) {
var reqUrl
, reqObj
+ , respObj
, params
, urlParams
, method
@@ -359,6 +363,8 @@ var App = function () {
// Buffered request-obj -- buffer the request data,
// and pass this proxy object to the controller
reqObj = new Request(req);
+ // Wrapped response-obj
+ respObj = new Response(resp);
finish = function (step) {
steps[step] = true;
@@ -396,18 +402,19 @@ var App = function () {
inFlightId = geddy.inFlight.addEntry({
request: req
, method: method
- , response: resp
+ , response: respObj
, accessTime: accessTime
});
- req._geddyId = inFlightId;
- resp._geddyId = inFlightId;
+ reqObj._geddyId = inFlightId;
+ respObj._geddyId = inFlightId;
// FIXME: Holy shit, all inline here
- resp.addListener('finish', function () {
- var id = resp._geddyId
+ // Probably should proxy events for wrapped Response obj
+ respObj.resp.addListener('finish', function () {
+ var id = respObj._geddyId
, entry = geddy.inFlight.getEntry(id)
, req = entry.request
- , stat = resp.statusCode
+ , stat = respObj.statusCode
, endTime = new Date()
, level = parseInt(stat, 10);
@@ -424,7 +431,7 @@ var App = function () {
'"' + entry.method + ' ' + reqUrl + ' ' +
req.httpVersion + '" ' +
stat + ' ' +
- (resp._length || '-') + ' ' +
+ (respObj._length || '-') + ' ' +
'"' + (req.headers['referer'] || '-') + '" ' +
'"' + (req.headers['user-agent'] || '-') + '" ');
@@ -529,21 +536,18 @@ var App = function () {
controller.app = self;
controller.request = reqObj;
- // Save a reference to the controller on the req to allow lookup
- // when running filters in Connect-middleware compat-mode. Sometimes
- // these functions are pre-bound, so "this" can't reference our
- // controller
reqObj.controller = controller;
+ controller.response = respObj;
+ respObj.controller = controller;
- controller.response = resp;
controller.method = method;
controller.params = params;
controller.name = params.controller;
controller.i18n = new i18n.I18n(controller);
// We have a controller instance; register it with the
// in-flight data
- geddy.inFlight.updateEntry(req._geddyId, {
+ geddy.inFlight.updateEntry(reqObj._geddyId, {
controller: controller
});
@@ -563,18 +567,16 @@ var App = function () {
else {
err = new errors.InternalServerError('No ' + params.action +
' action on ' + params.controller + ' controller.');
- errResp = new response.Response(resp);
- errResp.send(err.message, err.statusCode,
- {'Content-Type': 'text/html'});
+ controller = new ErrorController(err, reqObj, respObj);
+ controller.respond();
}
}
// no controller, 500 error
else {
err = new errors.InternalServerError('controller ' +
params.controller + ' not found.');
- errResp = new response.Response(resp);
- errResp.send(err.message, err.statusCode,
- {'Content-Type': 'text/html'});
+ controller = new ErrorController(err, reqObj, respObj);
+ controller.respond();
}
}
// Either static, 404, or 405
@@ -597,14 +599,16 @@ var App = function () {
// this point
if (fs.statSync(p).isDirectory()) {
// TODO: Make the name of any index file configurable
- p = path.join(p, 'index.html');
- if (utils.file.existsSync(p) && fs.statSync(p).isFile()) {
- staticResp.sendFile(p);
+ staticPath = path.join(staticPath, 'index.html');
+ if (utils.file.existsSync(staticPath) && fs.statSync(staticPath).isFile()) {
+ controller = new StaticFileController(staticPath, reqObj, respObj);
+ controller.respond();
}
}
// Path to an actual file. Just serve it up
- else if (fs.statSync(p).isFile()) {
- staticResp.sendFile(p);
+ else if (fs.statSync(staticPath).isFile()) {
+ controller = new StaticFileController(staticPath, reqObj, respObj);
+ controller.respond();
}
};
@@ -616,9 +620,8 @@ var App = function () {
else if (staticUrl.match('partials/') && utils.file.existsSync(partialsPath)) {
sendStaticFile(partialsPath);
}
- // Must be a 404 or 405
+ // 405?
else {
- // 405?
nonMethodRoutes = router.all(reqUrl);
if (nonMethodRoutes.length) {
// build a unique list of acceptable methods for this resource
@@ -636,13 +639,12 @@ var App = function () {
errResp = new response.Response(resp);
errResp.send( err.message, err.statusCode, {'Content-Type': 'text/html'} );
- // 404
}
- else{
+ // 404
+ else {
err = new errors.NotFoundError(reqUrl + ' not found.');
- errResp = new response.Response(resp);
- errResp.send(err.message, err.statusCode,
- {'Content-Type': 'text/html'});
+ controller = new ErrorController(err, reqObj, respObj);
+ controller.respond();
}
}
}
View
@@ -9,6 +9,9 @@ config = {
, workers: 2
// Port to listen on
, port: 4000
+// Default to no SSL and SPDY setup
+, spdy: null
+, ssl: null
// Set stdout to debug log-level
, debug: false
// Use worker-process rotation
@@ -44,11 +47,11 @@ config = {
defaultLocale: 'en-us'
, loadPaths: [path.normalize(cwd + '/config/locales')]
}
-// Default to no SSL and SPDY setup
-, spdy: null
-, ssl: null
// Default to localhost `hostname`
, hostname: 'localhost'
+// If not specifically set, will be constructed from
+// protocol + '://' + hostname + ':' + port
+, fullHostname: null
// Switch for making before/after filters compatible with
// Connect middleware
, connectCompatibility: false
View
@@ -17,7 +17,9 @@ config = new (function () {
, fileBaseName
, useCoffee
, appBaseConfig
- , appEnvConfig;
+ , appEnvConfig
+ , protocol
+ , fullHostname;
baseConfig = utils.mixin({}, require('./base_config'), true);
env = opts.environment || baseConfig.environment;
@@ -57,6 +59,19 @@ config = new (function () {
ret.rotateWorkers = false;
}
+ // Fix old null hostname configs
+ ret.hostname = ret.hostname || 'localhost';
+
+ // Construct fullHostname if not specifically set
+ if (!ret.fullHostname) {
+ protocol = ret.ssl ? 'https' : 'http';
+ fullHostname = protocol + '://' + ret.hostname;
+ if (ret.port != 80) {
+ fullHostname += ':' + ret.port;
+ }
+ ret.fullHostname = fullHostname;
+ }
+
return ret;
};
@@ -16,8 +16,8 @@
*
*/
var crypto = require('crypto')
- , response = require('./response')
- , Templater = require('./template').Templater;
+ , response = require('../response')
+ , Templater = require('../template').Templater;
/**
@name controller
@@ -113,7 +113,6 @@ controller.BaseController.prototype = new (function () {
var _addFilter
, _execFilters
, _negotiateContent
- , _doResponse
, _throwUndefinedFormatError
, _generateSameOriginToken
, _protectFromForgery;
@@ -285,48 +284,6 @@ controller.BaseController.prototype = new (function () {
};
};
- _doResponse = function (stat, headers, content) {
- // No repeatsies
- if (this.completed) {
- return;
- }
-
- this.completed = true;
-
- var self = this
- , r = new response.Response(this.response)
- , action = this.action
- , callback;
-
- callback = function () {
- // Set status and headers, can be overridded with after filters
- if (self.cookies) {
- headers['Set-Cookie'] = self.cookies.toArray();
- }
- r.setHeaders(stat, headers);
-
- // Run after filters, then finish out the response
- _execFilters.apply(self, [action, 'after', function () {
- if (self.method == 'HEAD') {
- r.finish();
- }
- else {
- r.finalize(content);
- }
- }]);
- };
-
- if (this.session) {
- // Save access time into session for expiry and
- // - verifying sameOriginToken
- this.session.set('accessTime', this.accessTime);
- this.session.close(callback);
- }
- else {
- callback();
- }
- };
-
_throwUndefinedFormatError = function () {
err = new geddy.errors.InternalServerError(
'Format not defined in response.formats.');
@@ -401,6 +358,48 @@ controller.BaseController.prototype = new (function () {
}
};
+ this._doResponse = function (stat, headers, content) {
+ // No repeatsies
+ if (this.completed) {
+ return;
+ }
+
+ this.completed = true;
+
+ var self = this
+ , r = this.response
+ , action = this.action
+ , callback;
+
+ callback = function () {
+ // Set status and headers, can be overridded with after filters
+ if (self.cookies) {
+ headers['Set-Cookie'] = self.cookies.toArray();
+ }
+ r.setHeaders(stat, headers);
+
+ // Run after filters, then finish out the response
+ _execFilters.apply(self, [action, 'after', function () {
+ if (self.method == 'HEAD') {
+ r.finish();
+ }
+ else {
+ r.finalize(content);
+ }
+ }]);
+ };
+
+ if (this.session) {
+ // Save access time into session for expiry and
+ // - verifying sameOriginToken
+ this.session.set('accessTime', this.accessTime);
+ this.session.close(callback);
+ }
+ else {
+ callback();
+ }
+ };
+
/*
*
* Public methods
@@ -502,7 +501,7 @@ controller.BaseController.prototype = new (function () {
}
}
- _doResponse.apply(this, [302, { 'Location': url }, '']);
+ this._doResponse(302, { 'Location': url }, '');
};
this.error = function (err) {
@@ -555,7 +554,7 @@ controller.BaseController.prototype = new (function () {
, callback;
callback = function (formattedContent) {
- _doResponse.apply(self, [200, {'Content-Type': contentType}, formattedContent]);
+ self._doResponse(200, {'Content-Type': contentType}, formattedContent);
};
// Error during content negotiation may result in an error response, so
Oops, something went wrong.

0 comments on commit 602ecf1

Please sign in to comment.