Got headless_client working with HTTPS and CDN caching.

This commit is contained in:
Nick Winter 2015-04-10 16:19:27 -07:00
parent e85c53ea42
commit ae4dec1468
2 changed files with 9 additions and 8 deletions

View file

@ -1,12 +1,12 @@
###
This file will simulate games on node.js by emulating the browser environment.
This file will simulate games on node.js by emulating the browser environment.
In order to use, followed these steps:
1. Setup dev environment as usual
2. Create a `login.coffee` file in coco which contains:
module.exports = username: 'email@example.com', password: 'password'
3. Run `./node_modules/coffee-script/bin/coffee ./headless_client.coffee`
Alternatively, if you wish only to simulate a single game run `coffee ./headless_client.coffee one-game`
Or, if you want to always simulate only one game, change the line below this to "true"
Or, if you want to always simulate only one game, change the line below this to "true". This takes way more bandwidth.
###
simulateOneGame = false
if process.argv[2] is 'one-game'
@ -29,7 +29,7 @@ options =
simulateOnlyOneGame: simulateOneGame
options.heapdump = require('heapdump') if options.heapdump
server = if options.testing then 'http://127.0.0.1:3000' else 'http://direct.codecombat.com'
server = if options.testing then 'http://127.0.0.1:3000' else 'https://codecombat.com'
# Use direct instead of live site because jQlone's requests proxy doesn't do caching properly and CloudFlare gets too aggressive.
# Disabled modules

View file

@ -1,5 +1,5 @@
#jQuery for node, reimplementated for compatibility purposes. Poorly.
#Leaves out all the dome stuff but allows ajax.
#Leaves out all the DOM stuff but allows ajax.
_ = require 'lodash'
request = require 'request'
Deferred = require 'JQDeferred'
@ -9,7 +9,7 @@ module.exports = $ = (input) ->
# Non-standard jQuery stuff. Don't use outside of server.
$._debug = false
$._server = 'http://direct.codecombat.com'
$._server = 'https://codecombat.com'
$._cookies = request.jar()
$.when = Deferred.when
@ -20,16 +20,17 @@ $.ajax = (options) ->
url = '/' + url unless url[0] is '/'
url = $._server + url
data = options.data
console.log 'Requesting: ' + JSON.stringify options if $._debug
console.log 'URL: ' + url if $._debug
if /db\/thang.type\/names/.test url
url += '?_=' + Math.random() # Make sure that the ThangType names don't get cached, since response varies based on parameters in a way that apparently doesn't work in this hacky implementation.
deferred = Deferred()
request
url: url
jar: $._cookies
json: options.parse
method: options.type
body: data
body: options.data
, (error, response, body) ->
console.log 'HTTP Request:' + JSON.stringify options if $._debug and not error
if responded
@ -48,7 +49,7 @@ $.ajax = (options) ->
deferred.promise().done(options.success).fail(options.error)
$.extend = (deep, into, from) ->
copy = _.clone(from, deep);
copy = _.clone(from, deep)
if into
_.assign into, copy
copy = into