Permalink
Browse files

bootstrap

  • Loading branch information...
1 parent 2e2f321 commit 2643ecf7017a4ca49aa3c89555191f774b5c2471 @vovazolotoy vovazolotoy committed Nov 8, 2011
View
@@ -1,40 +1,51 @@
+/**
+ * Enable modules. Modules are referenced by a relative or absolute path.
+ */
Johana.modules({
cache: MODPATH + 'cache'
});
+/**
+ * Initialize Johana, setting the default options.
+ *
+ * The following options are available:
+ *
+ * - string baseUrl path, and optionally domain, of your application NULL
+ * - boolean errors enable or disable error handling TRUE
+ * - boolean profile enable or disable internal profiling TRUE
+ * - boolean caching enable or disable internal caching FALSE
+ */
Johana.init({
baseUrl: 'http://johana.site',
- profile: false
+ profile: false,
+ http: {
+ host: "localhost",
+ listen: 8001
+ }
+// https: {
+// key: DOCROOT + '/certs/server.key',
+// cert: DOCROOT + '/certs/server.crt',
+// listen: 8001
+// }
});
/**
* Attach the file write to logging. Multiple writers are supported.
*/
Johana.log.attach(new LogFile(APPPATH + 'logs'), Log.ERROR);
-
Johana.log.attach(new LogConsole());
+/**
+ * Attach a file reader to config. Multiple readers are supported.
+ */
Johana.conf.attach(new ConfigFile());
-function testList(req, res) {
- Johana.log.add(Log.DEBUG, 'Request: ' + req.url);
- Johana.log.add(Log.ERROR, 'ERRO Request: ' + req.url);
+Johana.onRequest = function(req, res) {
+
+ Request.factory(req.url, req);
+ Johana.log.add(Log.ERROR, 'vova');
- //console.log(Request.factory(req.url, req));
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(View.factory('hello').render());
};
-
-require('http').createServer(function (req, res) {
- testList(req, res);
-}).listen(8001, "127.0.0.1");
-
-//var options = {
-// key: require('fs').readFileSync(DOCROOT + '/certs/server.key'),
-// cert: require('fs').readFileSync(DOCROOT + '/certs/server.crt')
-//};
-//
-//require('https').createServer(options, function (req, res) {
-// testList(req, res);
-//}).listen(8002);
@@ -264,6 +264,33 @@ JohanaCore.init = function(settings)
// Load the config
Johana.conf = Config.instance();
+
+ // Setup http server
+ var listen = 80; var host = "localhost";
+
+ if (settings['http'] !== undefined && settings['http']['listen'] !== undefined)
+ {
+ listen = settings['http']['listen'];
+ }
+ if (settings['http'] !== undefined && settings['http']['host'] !== undefined)
+ {
+ host = settings['http']['host'];
+ }
+
+ require('http').createServer(function(request, response) {
+ Johana.onRequest(request, response);
+ }).listen(listen, host);
+
+ if (settings['https'])
+ {
+ var httpsOptions = {
+ key: require('fs').readFileSync(settings['https']['key']),
+ cert: require('fs').readFileSync(settings['https']['cert'])
+ };
+ require('https').createServer(httpsOptions, function(request, response) {
+ Johana.onRequest(request, response);
+ }).listen(settings['https']['listen'], settings['https']['host']);
+ }
};
/**
@@ -607,5 +634,27 @@ JohanaCore.config = function(group)
}
};
+/**
+ * Returns the configuration array for the requested group. See
+ * [configuration files](johana/files/config) for more information.
+ *
+ * // Get all the configuration in config/database.js
+ * var config = Johana.config('database');
+ *
+ * // Get only the default connection configuration
+ * var default = Johana.config('database.default')
+ *
+ * // Get only the hostname of the default connection
+ * var host = Johana.config('database.default.connection.hostname')
+ * var host = Johana.config('database').default.connection.hostname
+ *
+ * @param String group name
+ * @return Config
+ */
+JohanaCore.onRequest = function(request, response)
+{
+ response.writeHead(200, {'Content-Type': 'text/html'});
+ response.end(View.factory('system/onrequest').render());
+};
module.exports = JohanaCore;
@@ -23,11 +23,6 @@ JohanaLog.DEBUG = 7;
JohanaLog.STRACE = 8;
/**
- * @var Boolean immediately write when logs are added
- */
-JohanaLog.writeOnAdd = true;
-
-/**
* @var Log Singleton instance container
*/
JohanaLog._instance = null;
@@ -45,9 +40,6 @@ JohanaLog.instance = function()
{
// Create a new instance
Log._instance = new Log();
-
- // Write the logs at shutdown
- //register_shutdown_function(array(Log::$_instance, 'write'));
}
return Log._instance;
@@ -149,11 +141,8 @@ JohanaLog.prototype.add = function(level, message, values)
body: message
});
- if (Log.writeOnAdd)
- {
- // Write logs as they are added
- this.write();
- }
+ // Write logs as they are added
+ this.write();
return this;
};
@@ -7,7 +7,10 @@
* @copyright (c) 2011 Johana Team
* @license http://johanaframework.org/license
*/
-JohanaLogWriter = function() {};
+JohanaLogWriter = function() {
+
+ this.id = Math.random();
+};
/**
* Numeric log level to string lookup table.
@@ -34,7 +37,7 @@ JohanaLogWriter.prototype._logLevels = {
*/
JohanaLogWriter.prototype.toString = function()
{
- return JSON.stringify(this);
+ return this.id.toString();
};
exports = module.exports = JohanaLogWriter; // End
@@ -22,6 +22,11 @@ JohanaRequest.userAgent = '';
JohanaRequest.clientIp = '0.0.0.0';
/**
+ * @var string trusted proxy server IPs
+ */
+JohanaRequest.trustedProxies = ['127.0.0.1', 'localhost', 'localhost.localdomain'];
+
+/**
* @var Request main request instance
*/
JohanaRequest.initial;
@@ -50,7 +55,7 @@ JohanaRequest.factory = function(uri, req)
var protocol, method, referrer, userAgent, clientIp, requestedWith, body = '';
// If this is the initial request
- if (1)// ! Request.initial)
+ if ( 1 )
{
if (req.method)
{
@@ -138,4 +138,19 @@ JohanaUrl.title = function(title, separator)
return title.replace(new RegExp('^' + sep), '').replace(new RegExp(sep+'$'), '');
};
+
+/**
+ * Convert a phrase to a URL-safe title.
+ *
+ * console.log(URL.title('My Blog Post')); // "my-blog-post"
+ *
+ * @param String title Phrase to convert
+ * @param String separator Word separator (any single character)
+ * @return String
+ */
+JohanaUrl.current = function()
+{
+ return Request_initial;
+};
+
module.exports = JohanaUrl; // End
@@ -0,0 +1,3 @@
+
+ <h3>Welcome to Johana</h3>
+ <p>For start just set your <strong>Johana.onRequest()</strong> hendler in bootstrap.js or other place.</p>
View
16 test.js
@@ -0,0 +1,16 @@
+
+
+function outerFunction()
+{
+ var rrr = 123;
+
+ innerFunction();
+}
+
+
+function innerFunction()
+{
+ console.log(rrr);
+}
+
+outerFunction();

0 comments on commit 2643ecf

Please sign in to comment.