Permalink
Browse files

added params from process.argv for Cloud9 support

  • Loading branch information...
1 parent 75980d3 commit 20f41d71e2010d1b45f2a6c2884d503420d1f2c2 M Alix committed Dec 13, 2012
View
6 .c9revisions/app.coffee.c9save
@@ -0,0 +1,6 @@
+{"ts":1355416616719,"silentsave":true,"restoring":false,"patch":[[{"diffs":[[1,"util = require(\"util\")\r\npath = require(\"path\")\r\nmodules = path.join __dirname, 'modules'\r\nconnect = require(\"connect\")\r\nsession = connect.session\r\ncookieParser = connect.cookieParser\r\nflatiron = require(\"flatiron\")\r\ndirector = require \"director\"\r\necstatic = require \"ecstatic\"\r\n#jade = require \"jade.plugin\"\r\n#bliss = require \"./lib/view.bliss.plugin.coffee\"\r\njshtml = require path.join(modules, \"view.jshtml.plugin.coffee\")\r\nparse = require path.join(modules, \"parse.plugin.coffee\")\r\nsession_helper = require path.join(modules, \"session_helper.coffee\")\r\n\r\napp = flatiron.app\r\napp.use flatiron.plugins.http\r\n\r\napp.http.before.push cookieParser(process.env.CookieParserSecret) # Set in your Environment...\r\napp.http.before.push session()\r\n\r\n#app.use jade.plugin, \r\n# dir: \"\" + __dirname + \"/views\",\r\n# ext: '.jade'\r\n\r\n#app.use bliss.plugin, \r\n# dir: \"\" + __dirname + \"/views\",\r\n# ext: '.bliss'\r\n\r\napp.use parse.plugin\r\n \r\napp.use jshtml.plugin, \r\n dir: \"\" + __dirname + \"/views\",\r\n ext: '.jshtml'\r\n\r\napp.http.before.push ecstatic(\r\n root: __dirname+'/assets',\r\n baseDir: 'public' \r\n )\r\n\r\napp.http.before.push (req,res) ->\r\n unless req.session.user\r\n req.session.user = false\r\n msg = util.inspect \r\n url: req.url\r\n session: req.session\r\n console.log \"[REQUEST] #{msg}\"\r\n\r\n res.emit 'next'\r\n\r\napp.router.get \"/\", ->\r\n session_helper.view_locals @req, {}, (options) =>\r\n app.render @res, 'index', options\r\n \r\napp.router.get \"/login\", ->\r\n session_helper.view_locals @req,\r\n title: \"login | aZoo.me\"\r\n isLogin: true\r\n , (options) =>\r\n app.render @res, \"login\", options\r\n\r\napp.router.post \"/login\", ->\r\n session_helper.login app, @req.body.username, @req.body.password, (err,user) =>\r\n if err\r\n delete @req.session.user\r\n session_helper.redirect_with_error_number @req, @res, err, \"/login\"\r\n else\r\n @req.session.user = user\r\n session_helper.redirect_with_success_number @req, @res, 0, \"/\"\r\n\r\napp.router.get \"/logout\", ->\r\n delete @req.session.user\r\n session_helper.redirect_with_success_number @req, @res, 0, \"/\"\r\n\r\nport = process.env.PORT or 3000\r\nhost = process.env.IP\r\n\r\napp.start port, host, (err) ->\r\n console.log \"[SERVER] Started at #{host}:#{port}...\"\r\n properties = (prop for prop of app)\r\n app.parse.list \"Users\", (err, data) ->\r\n app.users = data.results\r\n console.log \"[SERVER] Loaded #{app.users.length} users\"\r\n #for property of app.users\r\n # console.log property \r\n \r\n"]],"start1":0,"start2":0,"length1":0,"length2":2594}]],"length":2594}
+{"contributors":[],"silentsave":false,"ts":1355416652412,"patch":[[{"diffs":[[0,"eParser("],[1,"process.argv[2] or "],[0,"process."]],"start1":726,"start2":726,"length1":16,"length2":35},{"diffs":[[0,"erSecret"],[1," or \"Secret\""],[0,") # Set "]],"start1":775,"start2":775,"length1":16,"length2":28}]],"length":2625,"saved":false}
+{"ts":1355416918536,"patch":[[{"diffs":[[1,"ParamNotSet = (p,n) ->\r\n err = new Error(\"Environment Variable Not Set Error! Set #{p} or pass it in as the #{n} argument)\r\n throw err\r\n \r\n"],[0,"util "]],"start1":0,"start2":0,"length1":12,"length2":160},{"diffs":[[0," or "],[-1,"\"Secret\""],[1,"ParamNotSet(\"CookieParserSecret\", \"1st\")"],[0,") # "]],"start1":931,"start2":931,"length1":16,"length2":48}]],"length":2805,"saved":false}
+{"ts":1355416938144,"patch":[[{"diffs":[[0,"\")) "],[-1,"# Set in your Environment..."],[0,"\r\nap"]],"start1":973,"start2":973,"length1":36,"length2":8}]],"length":2777,"saved":false}
+{"ts":1355417007207,"patch":[[{"diffs":[[-1,"ParamNotSet = (p,n) ->\r\n err = new Error(\"Environment Variable Not Set Error! Set #{p} or pass it in as the #{n} argument)\r\n throw err\r\n \r\n"],[0,"util"]],"start1":0,"start2":0,"length1":152,"length2":4},{"diffs":[[0,"ee\")\r\n\r\n"],[1,"ParamNotSet = (p,n) ->\r\n err = new Error(\"Environment Variable Not Set Error! Set #{p} or pass it in as the #{n} argument\")\r\n throw err\r\n\r\n"],[0,"app = fl"]],"start1":639,"start2":639,"length1":16,"length2":161}]],"length":2774,"saved":false}
+{"ts":1355417080996,"patch":[[{"diffs":[[0,"ser("],[-1,"process.argv[2] or "],[0,"proc"]],"start1":875,"start2":875,"length1":27,"length2":8},{"diffs":[[0,"erSecret"],[1," or process.argv[2]"],[0," or Para"]],"start1":901,"start2":901,"length1":16,"length2":35}]],"length":2774,"saved":false}
View
6 .c9revisions/modules/parse.plugin.coffee.c9save
@@ -0,0 +1,6 @@
+{"ts":1355416660552,"silentsave":true,"restoring":false,"patch":[[{"diffs":[[1,"util = require(\"util\")\r\ninspect = util.inspect\r\nlog = (obj) ->\r\n console.log \"[PARSE] #{inspect(obj)}\"\r\nfs = require('fs')\r\n\r\nclass SessionImageCache\r\n @is_same: (req, url) ->\r\n noneMatchHeader = req.headers['if-none-match']\r\n unless noneMatchHeader\r\n return false\r\n\r\n urls = req.session.image_cache\r\n unless urls\r\n return false\r\n\r\n etag = urls[url]\r\n return noneMatchHeader is etag\r\n\r\n @store: (req, url) ->\r\n noneMatchHeader = req.headers['if-none-match']\r\n unless noneMatchHeader\r\n return\r\n urls = req.session.image_cache or {}\r\n urls[url] = noneMatchHeader\r\n req.session.image_cache = urls\r\n\r\nclass Parse\r\n constructor: (application_id, master_key) ->\r\n @application_id = application_id\r\n @master_key = master_key\r\n @api_protocol = request = require('request')\r\n @api_host = \"api.parse.com\"\r\n @api_port = 443\r\n #if process.env.http_proxy\r\n # proxy = require('./proxy')\r\n # parts = process.env.http_proxy.replace('http://','').split(':')\r\n # @agent = proxy.createAgent(parts[0],parts[1])\r\n #else\r\n @agent = false\r\n\r\n parseRequest: (method, path, data, callback) ->\r\n auth = \"Basic \" + new Buffer(@application_id + \":\" + @master_key).toString(\"base64\")\r\n headers =\r\n Authorization: auth\r\n Connection: \"Keep-alive\"\r\n\r\n options =\r\n method: method\r\n uri: \"https://api.parse.com:443\" + path\r\n headers: headers\r\n json: method isnt \"FILE\"\r\n\r\n switch method\r\n when \"GET\"\r\n options.qs = data if data\r\n when \"POST\", \"PUT\"\r\n options.body = JSON.stringify(data)\r\n options.headers[\"Content-type\"] = \"application/json\"\r\n options.headers[\"Content-length\"] = options.body.length\r\n when \"DELETE\"\r\n options.headers[\"Content-length\"] = 0\r\n when \"FILE\"\r\n options.method = \"POST\"\r\n options.headers[\"Content-length\"] = data.size\r\n options.headers[\"Content-type\"] = data.type\r\n options.body = fs.readFileSync(data.path)\r\n data = false\r\n else\r\n throw new Error(\"Unknown method, \\\"\" + method + \"\\\"\")\r\n\r\n if @agent\r\n options.agent = @agent\r\n #options.tunnel = true\r\n\r\n msg = \"[PARSE][#{method}] Calling #{options.uri}%s ->\\n\\t%s\"\r\n console.log(msg, (if options.agent then ' with proxy' else ''), (if data then util.inspect(data) else ''))\r\n try\r\n req = @api_protocol(options, (error, res, body) ->\r\n unless callback\r\n callback = (err,body) ->\r\n {}\r\n\r\n if error\r\n console.log \"[PARSE][ERROR] \" + error\r\n return callback(error)\r\n\r\n if res.statusCode < 200 or res.statusCode >= 300\r\n msg = \"HTTP error \" + res.statusCode\r\n console.log \"[PARSE][ERROR] \" + msg\r\n err = new Error(msg)\r\n err.arguments = arguments\r\n err.type = res.statusCode\r\n err.options = options\r\n err.body = body\r\n return callback(err)\r\n\r\n #console.log \"[PARSE][OK] #{util.inspect(body).replace(\"\\n\", \" \")}\"\r\n callback null, body\r\n )\r\n catch exc\r\n callback(exc)\r\n\r\n insert: (className, object, callback) ->\r\n this.parseRequest.call this, \"POST\", \"/1/classes/\" + className, object, callback\r\n\r\n list: (className, callback) ->\r\n this.parseRequest.call this, \"GET\", \"/1/classes/\" + className, null, callback\r\n\r\n find: (className, query, paging, callback) ->\r\n unless callback\r\n callback = paging\r\n paging = null\r\n if typeof query is \"string\"\r\n this.parseRequest.call this, \"GET\", \"/1/classes/\" + className + \"/\" + query, null, callback\r\n else\r\n obj =\r\n where: JSON.stringify(query)\r\n if paging\r\n obj.limit = paging.limit\r\n this.parseRequest.call this, \"GET\", \"/1/classes/\" + className, obj, callback\r\n\r\n update: (className, objectId, object, callback) ->\r\n this.parseRequest.call this, \"PUT\", \"/1/classes/\" + className + \"/\" + objectId, object, callback\r\n\r\n delete: (className, objectId, callback) ->\r\n this.parseRequest.call this, \"DELETE\", \"/1/classes/\" + className + \"/\" + objectId, null, callback\r\n\r\n uploadFile: (file_info, callback) ->\r\n this.parseRequest.call this, \"FILE\", \"/1/files/#{file_info.name}\", file_info, callback\r\n\r\n deleteFile: (name, callback) ->\r\n this.parseRequest.call this, \"DELETE\", \"/1/files/#{name}\", null, callback\r\n\r\n sendFile: (url, req, res) ->\r\n if @agent\r\n #options.agent = @agent\r\n return res.redirect 303, url\r\n\r\n try\r\n\r\n if SessionImageCache.is_same(req, url)\r\n log\r\n send: url\r\n cache: req.session.image_cache\r\n status: 304\r\n return res.send 304\r\n\r\n @api_protocol(url).pipe(res)\r\n SessionImageCache.store(req, url)\r\n log\r\n send: url\r\n cache: req.session.image_cache\r\n status: 200\r\n\r\n catch exc\r\n console.log \"[PARSE][SEND_FILE] Exception: #{util.inspect(exc)}\"\r\n res.send 500\r\n\r\n now_id: ->\r\n now = new Date();\r\n jsonDate = now.toJSON()\r\n return jsonDate\r\n\r\n noop: (className, object, callback) ->\r\n callback(null, 'NOOP:' + JSON.stringify(object) )\r\n\r\nattach = (options) ->\r\n self = this\r\n self.parse = new Parse(process.env.ParseApplicationId, process.env.ParseMasterKey) # Set in your environment\r\n\r\nexports.plugin =\r\n name: \"parse.plugin\"\r\n attach: attach"]],"start1":0,"start2":0,"length1":0,"length2":5358}]],"length":5358}
+{"contributors":[],"silentsave":false,"ts":1355416875166,"patch":[[{"diffs":[[0,"t) )\r\n\r\n"],[1,"ParamNotSet = (p,n) ->\r\n err = new Error(\"Environment Variable Not Set Error! Set #{p} or pass it in as the #{n} argument)\r\n\r\n"],[0,"attach ="]],"start1":5140,"start2":5140,"length1":16,"length2":145},{"diffs":[[0,"w Parse("],[1,"process.argv[3] or "],[0,"process."]],"start1":5332,"start2":5332,"length1":16,"length2":35},{"diffs":[[0,"onId"],[-1,", process.env.ParseMasterKey"],[1," or ParamNotSet(\"ParseApplicationId\",\"2nd\"), process.argv[4] or process.env.ParseMasterKey or ParamNotSet(\"ParseMasterKey\",\"3rd\")"],[0,") # "]],"start1":5385,"start2":5385,"length1":36,"length2":137}]],"length":5607,"saved":false}
+{"ts":1355416931849,"patch":[[{"diffs":[[0,"gument)\r"],[1,"\n throw err\r"],[0,"\n\r\nattac"]],"start1":5266,"start2":5266,"length1":16,"length2":31},{"diffs":[[0,"\")) "],[-1,"# Set in your environment"],[0,"\r\n\r\n"]],"start1":5531,"start2":5531,"length1":33,"length2":8}]],"length":5597,"saved":false}
+{"ts":1355417012292,"patch":[[{"diffs":[[0,"argument"],[1,"\""],[0,")\r\n t"]],"start1":5264,"start2":5264,"length1":16,"length2":17}]],"length":5598,"saved":false}
+{"ts":1355417061517,"patch":[[{"diffs":[[0,"rse("],[-1,"process.argv[3] or "],[0,"proc"]],"start1":5352,"start2":5352,"length1":27,"length2":8},{"diffs":[[0,"cationId"],[1," or process.argv[3]"],[0," or Para"]],"start1":5378,"start2":5378,"length1":16,"length2":35}]],"length":5598,"saved":false}
+{"ts":1355417093761,"patch":[[{"diffs":[[0,"ess."],[-1,"argv[4] or process.env.ParseMasterKey"],[1,"env.ParseMasterKey or process.argv[4]"],[0," or "]],"start1":5454,"start2":5454,"length1":45,"length2":45}]],"length":5598,"saved":false}
View
5 .c9revisions/server.js.c9save
@@ -0,0 +1,5 @@
+{"ts":1355416290629,"silentsave":true,"restoring":false,"patch":[[{"diffs":[[1,"require(\"coffee-script\"); \r\n\r\nvar app = require(\"./app.coffee\");\r\n\r\n\r\n"]],"start1":0,"start2":0,"length1":0,"length2":70}]],"length":70}
+{"contributors":[],"silentsave":false,"ts":1355416327575,"patch":[[{"diffs":[[0,"\"); \r\n\r\n"],[1,"console.log(process.argv[2]);\r\n\r\n"],[0,"var app "]],"start1":22,"start2":22,"length1":16,"length2":49}]],"length":103,"saved":false}
+{"ts":1355416341910,"patch":[[{"diffs":[[-1,"require(\"coffee-script\"); \r\n\r\nconsole.log(process.argv[2]);"],[1,"console.log(process.argv[2]);\r\n\r\nrequire(\"coffee-script\"); "],[0,"\r\n\r\n"]],"start1":0,"start2":0,"length1":63,"length2":63}]],"length":103,"saved":false}
+{"ts":1355416576218,"patch":[[{"diffs":[[0,"gv[2]);\r"],[1,"\nconsole.log(process.argv[3]);\r\nconsole.log(process.argv[4]);\r"],[0,"\n\r\nrequi"]],"start1":22,"start2":22,"length1":16,"length2":78}]],"length":165,"saved":false}
+{"ts":1355416612312,"patch":[[{"diffs":[[-1,"console.log(process.argv[2]);\r\nconsole.log(process.argv[3]);\r\nconsole.log(process.argv[4]);\r\n\r\n"],[0,"requ"]],"start1":0,"start2":0,"length1":99,"length2":4}]],"length":70,"saved":false}
View
6 app.coffee
@@ -13,10 +13,14 @@ jshtml = require path.join(modules, "view.jshtml.plugin.coffee")
parse = require path.join(modules, "parse.plugin.coffee")
session_helper = require path.join(modules, "session_helper.coffee")
+ParamNotSet = (p,n) ->
+ err = new Error("Environment Variable Not Set Error! Set #{p} or pass it in as the #{n} argument")
+ throw err
+
app = flatiron.app
app.use flatiron.plugins.http
-app.http.before.push cookieParser(process.env.CookieParserSecret) # Set in your Environment...
+app.http.before.push cookieParser(process.env.CookieParserSecret or process.argv[2] or ParamNotSet("CookieParserSecret", "1st"))
app.http.before.push session()
#app.use jade.plugin,
View
6 modules/parse.plugin.coffee
@@ -165,9 +165,13 @@ class Parse
noop: (className, object, callback) ->
callback(null, 'NOOP:' + JSON.stringify(object) )
+ParamNotSet = (p,n) ->
+ err = new Error("Environment Variable Not Set Error! Set #{p} or pass it in as the #{n} argument")
+ throw err
+
attach = (options) ->
self = this
- self.parse = new Parse(process.env.ParseApplicationId, process.env.ParseMasterKey) # Set in your environment
+ self.parse = new Parse(process.env.ParseApplicationId or process.argv[3] or ParamNotSet("ParseApplicationId","2nd"), process.env.ParseMasterKey or process.argv[4] or ParamNotSet("ParseMasterKey","3rd"))
exports.plugin =
name: "parse.plugin"

0 comments on commit 20f41d7

Please sign in to comment.