penguin/AstroJS

Javascript framework for my blog

commit 3b898d0a63898a0474aadf9e465f784c515a84ca

author斟酌 鵬兄 <tgckpg@gmail.com>
date2015-11-24T11:30:53Z
subjectHttps handling
commit 3b898d0a63898a0474aadf9e465f784c515a84ca
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2015-11-24T11:30:53Z

    Https handling
---
 botan-start.py                       |  8 +++++++-
 botanjs/src/System/Global.js         |  3 +++
 botanjs/src/System/utils/_this.js    | 23 +++++++++++++++++++++++
 botanjs/src/externs/System.Global.js |  3 +++
 botanjs/src/externs/System.utils.js  |  2 ++
 5 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/botan-start.py b/botan-start.py
index 4e9fce3..ad7b45e 100755
--- a/botan-start.py
+++ b/botan-start.py
@@ -65,7 +65,13 @@ if __name__ == "__main__":
 		, "beat"
 		, "-l"
 		, "info"
-	]).communicate()
+	])
+
+	import logging
+	logging.basicConfig(
+		filename = os.path.join( config["Paths"]["Log"], "access.log" )
+		, level = logging.DEBUG
+	)
 
 	WebAPI(
 		jsCache = config["Paths"]["Cache"]
diff --git a/botanjs/src/System/Global.js b/botanjs/src/System/Global.js
index 3f262d6..5be52eb 100644
--- a/botanjs/src/System/Global.js
+++ b/botanjs/src/System/Global.js
@@ -10,7 +10,10 @@
 	var IE = Boolean( document[ "all" ] );
 	var ALLOWED_ORIGINS = window[ "allowed_origins" ] || [];
 
+	var SECURE_HTTP = window.location.href.match( /^https:\/\// );
+
 	ns[ NS_EXPORT ]( EX_READONLY_GETTER, "debug", debug );
 	ns[ NS_EXPORT ]( EX_CONST, "IE", IE );
 	ns[ NS_EXPORT ]( EX_CONST, "ALLOWED_ORIGINS", ALLOWED_ORIGINS );
+	ns[ NS_EXPORT ]( EX_CONST, "SECURE_HTTP", SECURE_HTTP );
 })();
diff --git a/botanjs/src/System/utils/_this.js b/botanjs/src/System/utils/_this.js
index 32ca158..c92d4c9 100644
--- a/botanjs/src/System/utils/_this.js
+++ b/botanjs/src/System/utils/_this.js
@@ -1,5 +1,7 @@
 (function(){
 	var ns = __namespace( "System.utils" );
+	var Global = __import( "System.Global" );
+
 
 	// Get prop from obj if obj.<prop> is <type>
 	var objGetProp = function ( obj, prop, type )
@@ -35,7 +37,28 @@
 		}
 	};
 
+	var SiteProto = function( path )
+	{
+		if( path.match( /^https?:\/\// ) )
+		{
+			if( Global.SECURE_HTTP )
+			{
+				return path.replace( /^http:\/\//, "https://" );
+			}
+			else
+			{
+				return path.replace( /^https:\/\//, "http://" );
+			}
+		}
+		else
+		{
+			return "http" + ( Global.SECURE_HTTP ? "s" : "" ) + "://" + path;;
+		}
+	};
+
 	ns[ NS_EXPORT ]( EX_FUNC, "objGetProp", objGetProp );
 	ns[ NS_EXPORT ]( EX_FUNC, "objSearch", objSearch );
 	ns[ NS_EXPORT ]( EX_FUNC, "objMap", objMap );
+
+	ns[ NS_EXPORT ]( EX_FUNC, "siteProto", SiteProto );
 })();
diff --git a/botanjs/src/externs/System.Global.js b/botanjs/src/externs/System.Global.js
index 4a725d0..75784c7 100644
--- a/botanjs/src/externs/System.Global.js
+++ b/botanjs/src/externs/System.Global.js
@@ -6,3 +6,6 @@ System.Global.debug;
 
 /** @type {Boolean} */
 System.Global.IE;
+
+/** @type {Boolean} */
+System.Global.SECURE_HTTP;
diff --git a/botanjs/src/externs/System.utils.js b/botanjs/src/externs/System.utils.js
index 2c1eb90..2ac9985 100644
--- a/botanjs/src/externs/System.utils.js
+++ b/botanjs/src/externs/System.utils.js
@@ -7,3 +7,5 @@ System.utils.objGetProp;
 System.utils.objSearch;
 /** @type {Function} */
 System.utils.objMap;
+/** @type {Function} */
+System.utils.siteProto;