diff --git a/app/templates/teachers/convert-to-teacher-account-view.jade b/app/templates/teachers/convert-to-teacher-account-view.jade index bafdf37f2..215a0f5ef 100644 --- a/app/templates/teachers/convert-to-teacher-account-view.jade +++ b/app/templates/teachers/convert-to-teacher-account-view.jade @@ -34,7 +34,7 @@ block content .col-md-4.col-sm-6 #email-form-group.form-group label.control-label(data-i18n="general.email") - input.form-control(disabled=true value=me.get('email')) + input.form-control(name='email' disabled=true value=me.get('email')) .row.m-y-2 .col-md-offset-2.col-md-4.col-sm-6 diff --git a/package.json b/package.json index c5a0c4377..0f28fce31 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ "nodemon": "nodemon", "jasmine-node": "jasmine-node", "multicore": "coffee multicore.coffee", - "jasmine": "jasmine" + "jasmine": "jasmine", + "proxy": "COCO_PROXY='true' nodemon" }, "main": "index.js", "keywords": [ @@ -99,6 +100,7 @@ "compressible": "~1.0.1", "css-brunch": "^1.7.0", "fs-extra": "^0.26.2", + "http-proxy": "^1.13.2", "jade-brunch": "1.7.5", "jasmine": "^2.4.1", "javascript-brunch": "> 1.0 < 1.8", diff --git a/server/commons/queue.coffee b/server/commons/queue.coffee index 312f60a6e..5137bef01 100644 --- a/server/commons/queue.coffee +++ b/server/commons/queue.coffee @@ -140,7 +140,7 @@ class MongoQueueClient _createMongoConnection: -> @mongooseConnection = mongoose.createConnection @databaseAddress - @mongooseConnection.on 'error', -> log.error 'There was an error connecting to the queue in MongoDB' + @mongooseConnection.on 'error', -> log.error 'There was an error connecting to the queue in MongoDB' unless config.proxy @mongooseConnection.once 'open', -> log.info 'Successfully connected to MongoDB queue!' _generateMessageModel: -> diff --git a/server_config.coffee b/server_config.coffee index 0d936c74e..daa93949e 100644 --- a/server_config.coffee +++ b/server_config.coffee @@ -1,6 +1,7 @@ config = {} config.unittest = global.testing +config.proxy = process.env.COCO_PROXY config.tokyo = process.env.TOKYO or false config.saoPaulo = process.env.SAOPAULO or false diff --git a/server_setup.coffee b/server_setup.coffee index 6d84fd7e4..9f075e26d 100644 --- a/server_setup.coffee +++ b/server_setup.coffee @@ -48,7 +48,9 @@ developmentLogging = (tokens, req, res) -> else if status >= 300 then color = 36 elapsed = (new Date()) - req._startTime elapsedColor = if elapsed < 500 then 90 else 31 - "\x1b[90m#{req.method} #{req.originalUrl} \x1b[#{color}m#{res.statusCode} \x1b[#{elapsedColor}m#{elapsed}ms\x1b[0m" + s = "\x1b[90m#{req.method} #{req.originalUrl} \x1b[#{color}m#{res.statusCode} \x1b[#{elapsedColor}m#{elapsed}ms\x1b[0m" + s += ' (proxied)' if req.proxied + return s setupErrorMiddleware = (app) -> app.use (err, req, res, next) -> @@ -86,6 +88,8 @@ setupExpressMiddleware = (app) -> express.logger.format('dev', developmentLogging) app.use(express.logger('dev')) app.use(express.static(path.join(__dirname, 'public'), maxAge: 0)) # CloudFlare overrides maxAge, and we don't want local development caching. + + setupProxyMiddleware app # TODO: Flatten setup into one function. This doesn't fit its function name. app.use(useragent.express()) app.use(express.favicon()) @@ -216,6 +220,7 @@ exports.setupLogging = -> logging.setup() exports.connectToDatabase = -> + return if config.proxy database.connect() exports.setupMailchimp = -> @@ -230,3 +235,18 @@ exports.setExpressConfigurationOptions = (app) -> app.set('view options', { layout: false }) app.set('env', if config.isProduction then 'production' else 'development') app.set('json spaces', 0) if config.isProduction + +setupProxyMiddleware = (app) -> + return if config.isProduction + return unless config.proxy + httpProxy = require 'http-proxy' + proxy = httpProxy.createProxyServer({ + target: 'https://direct.codecombat.com' + secure: false + }) + log.info 'Using dev proxy server' + app.use (req, res, next) -> + req.proxied = true + proxy.web req, res, (e) -> + console.warn("Failed to proxy: ", e) + next() diff --git a/test/app/views/teachers/ConvertToTeacherAccountView.spec.coffee b/test/app/views/teachers/ConvertToTeacherAccountView.spec.coffee index 166dab1a7..45797cd18 100644 --- a/test/app/views/teachers/ConvertToTeacherAccountView.spec.coffee +++ b/test/app/views/teachers/ConvertToTeacherAccountView.spec.coffee @@ -136,6 +136,7 @@ describe 'ConvertToTeacherAccountView (/teachers/update-account)', -> attrs = JSON.parse(request.params) expect(attrs.properties?.firstName).toBe('Mr') expect(attrs.properties?.siteOrigin).toBe('convert teacher') + expect(attrs.properties?.email).toBe('some@email.com') it 'redirects to /teachers/classes', -> request = jasmine.Ajax.requests.mostRecent()