From eec1888b22f0e010eba7f17cbf22a8a9ecb1153a Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Thu, 17 Apr 2014 10:12:23 -0700 Subject: [PATCH] gzipping when in production but not going through Cloudflare. --- app/views/editor/level/thangs_tab_view.coffee | 8 ++++---- config.coffee | 1 + package.json | 3 ++- server_setup.coffee | 20 ++++++------------- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/app/views/editor/level/thangs_tab_view.coffee b/app/views/editor/level/thangs_tab_view.coffee index 5c5ca8dbd..b4ddc0e0f 100644 --- a/app/views/editor/level/thangs_tab_view.coffee +++ b/app/views/editor/level/thangs_tab_view.coffee @@ -426,11 +426,11 @@ module.exports = class ThangsTabView extends View @editThangView = null @onThangsChanged() @$el.find('.thangs-column').show() - + preventDefaultContextMenu: (e) -> return unless $(e.target).closest('#canvas-wrapper').length e.preventDefault() - + onSpriteContextMenu: (e) -> {clientX, clientY} = e.originalEvent.nativeEvent if @addThangType @@ -439,11 +439,11 @@ module.exports = class ThangsTabView extends View $('#duplicate a').html 'Duplicate' $('#contextmenu').css { position: 'fixed', left: clientX, top: clientY } $('#contextmenu').show() - + onDeleteClicked: (e) -> $('#contextmenu').hide() @deleteSelectedExtantThang e - + onDuplicateClicked: (e) -> $('#contextmenu').hide() if !@addThangType diff --git a/config.coffee b/config.coffee index 27c476980..b95413164 100644 --- a/config.coffee +++ b/config.coffee @@ -11,6 +11,7 @@ exports.config = ignored: (path) -> startsWith(sysPath.basename(path), '_') workers: enabled: false # turned out to be much, much slower than without workers + sourceMaps: true files: javascripts: defaultExtension: 'coffee' diff --git a/package.json b/package.json index ee0dcc201..d4c3fb6c9 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,8 @@ "karma-requirejs": "~0.2.1", "karma-phantomjs-launcher": "~0.1.1", "karma": "~0.10.9", - "karma-coverage": "~0.1.4" + "karma-coverage": "~0.1.4", + "compressible": "~1.0.1" }, "license": "MIT for the code, and CC-BY for the art and music", "private": true, diff --git a/server_setup.coffee b/server_setup.coffee index d8dcd1c03..7fdddae4c 100644 --- a/server_setup.coffee +++ b/server_setup.coffee @@ -3,7 +3,8 @@ path = require 'path' authentication = require 'passport' useragent = require 'express-useragent' fs = require 'graceful-fs' -log = require('winston') +log = require 'winston' +compressible = require 'compressible' database = require './server/commons/database' baseRoute = require './server/routes/base' @@ -11,17 +12,7 @@ user = require './server/users/user_handler' logging = require './server/commons/logging' config = require './server_config' auth = require './server/routes/auth' -UserHandler = require('./server/users/user_handler') - -###Middleware setup functions implementation### -# 2014-03-03: Try not using this and see if it's still a problem -#setupRequestTimeoutMiddleware = (app) -> -# app.use (req, res, next) -> -# req.setTimeout 15000, -> -# console.log 'timed out!' -# req.abort() -# self.emit('pass',message) -# next() +UserHandler = require './server/users/user_handler' productionLogging = (tokens, req, res) -> status = res.statusCode @@ -36,10 +27,12 @@ productionLogging = (tokens, req, res) -> null setupExpressMiddleware = (app) -> - #setupRequestTimeoutMiddleware app if config.isProduction express.logger.format('prod', productionLogging) app.use(express.logger('prod')) + app.use express.compress filter: (req, res) -> + return false if req.headers.host is 'codecombat.com' # Cloudflare will gzip it for us on codecombat.com + compressible res.getHeader('Content-Type') else app.use(express.logger('dev')) app.use(express.static(path.join(__dirname, 'public'))) @@ -50,7 +43,6 @@ setupExpressMiddleware = (app) -> app.use(express.bodyParser()) app.use(express.methodOverride()) app.use(express.cookieSession({secret:'defenestrate'})) - #app.use(express.compress()) if config.isProduction # just let Cloudflare do it setupPassportMiddleware = (app) -> app.use(authentication.initialize())