<commit_before>#
# Sets up intial project settings, middleware, mounted apps, and
# global configuration such as overriding Backbone.sync and
# populating sharify data
#

{ API_URL, NODE_ENV, ARTSY_ID, ARTSY_SECRET, SESSION_SECRET,
  SESSION_COOKIE_MAX_AGE, PORT, ASSET_PATH, FACEBOOK_APP_NAMESPACE,
  MOBILE_MEDIA_QUERY, MOBILE_URL, APP_URL, OPENREDIS_URL, DEFAULT_CACHE_TIME,
  CANONICAL_MOBILE_URL, IMAGES_URL_PREFIX, SECURE_IMAGES_URL,
  GOOGLE_ANALYTICS_ID, MIXPANEL_ID, SNOWPLOW_COLLECTOR_HOST, GOOGLE_SEARCH_CX,
  GOOGLE_SEARCH_KEY, COOKIE_DOMAIN, AUTO_GRAVITY_LOGIN, GOOGLE_MAPS_API_KEY,
  ADMIN_URL, CMS_URL, MAX_SOCKETS, ARTWORK_EMBED_URL, DELTA_HOST,
  ENABLE_AB_TEST, KIOSK_MODE, KIOSK_PAGE, SESSION_COOKIE_KEY, SENTRY_DSN,
  SENTRY_PUBLIC_DSN, SHOW_AUCTIONS_IN_HEADER, EMPTY_COLLECTION_SET_ID,
  GEMINI_S3_ACCESS_KEY, GEMINI_APP, GEMINI_ACCOUNT_KEY, BIDDER_H1_COPY,
  BIDDER_H2_COPY, APPLICATION_NAME, EMBEDLY_KEY, DISABLE_IMAGE_PROXY,
  POSITRON_URL } = config = require "../config"
{ parse, format } = require 'url'
_ = require 'underscore'
express = require "express"
Backbone = require "backbone"
sharify = require "sharify"
http = require 'http'
path = require "path"
artsyPassport = require 'artsy-passport'
artsyXappMiddlware = require 'artsy-xapp-middleware'
redirectMobile = require './middleware/redirect_mobile'
proxyGravity = require './middleware/proxy_to_gravity'
proxyReflection = require './middleware/proxy_to_reflection'
proxySitemaps = require './middleware/proxy_sitemaps'
localsMiddleware = require './middleware/locals'
micrositeMiddleware = require './middleware/microsite'
ensureSSL = require './middleware/ensure_ssl'
escapedFragmentMiddleware = require './middleware/escaped_fragment'
sameOriginMiddleware = require './middleware/same_origin'
hstsMiddleware = require './middleware/hsts'
unsupportedBrowserCheck = require "./middleware/unsupported_browser"
flash = require 'connect-flash'
flashMiddleware = require './middleware/flash'
bodyParser = require 'body-parser'
cookieParser = require 'cookie-parser'
session = require 'cookie-session'
favicon = require 'serve-favicon'
logger = require 'morgan'
editRequest = require './edit_request'
raven = require 'raven'
fs = require 'graceful-fs'
artsyError = require 'artsy-error-handler'
cache = require './cache'

# Setup sharify constants & require dependencies that use sharify data
sharify.data =
  JS_EXT: (if ("production" is NODE_ENV or "staging" is NODE_ENV) then ".min.js.cgz" else ".js")
  CSS_EXT: (if ("production" is NODE_ENV or "staging" is NODE_ENV) then ".min.css.cgz" else ".css")
  ASSET_PATH: ASSET_PATH
  APP_URL: APP_URL
  POSITRON_URL: POSITRON_URL
  API_URL: API_URL
  NODE_ENV: NODE_ENV
  MOBILE_MEDIA_QUERY: MOBILE_MEDIA_QUERY
  CANONICAL_MOBILE_URL: CANONICAL_MOBILE_URL
  MOBILE_URL: MOBILE_URL
  FACEBOOK_APP_NAMESPACE: FACEBOOK_APP_NAMESPACE
  SECURE_IMAGES_URL: SECURE_IMAGES_URL
  IMAGES_URL_PREFIX: IMAGES_URL_PREFIX
  GOOGLE_ANALYTICS_ID: GOOGLE_ANALYTICS_ID
  MIXPANEL_ID: MIXPANEL_ID
  SNOWPLOW_COLLECTOR_HOST: SNOWPLOW_COLLECTOR_HOST
  AUTO_GRAVITY_LOGIN: AUTO_GRAVITY_LOGIN
  GOOGLE_MAPS_API_KEY: GOOGLE_MAPS_API_KEY
  ADMIN_URL: ADMIN_URL
  CMS_URL: CMS_URL
  DELTA_HOST: DELTA_HOST
  ENABLE_AB_TEST: ENABLE_AB_TEST
  KIOSK_PAGE: KIOSK_PAGE
  KIOSK_MODE: KIOSK_MODE
  EMPTY_COLLECTION_SET_ID: EMPTY_COLLECTION_SET_ID
  GEMINI_S3_ACCESS_KEY: GEMINI_S3_ACCESS_KEY
  GEMINI_APP: GEMINI_APP
  GEMINI_ACCOUNT_KEY: GEMINI_ACCOUNT_KEY
  BIDDER_H1_COPY: BIDDER_H1_COPY
  BIDDER_H2_COPY: BIDDER_H2_COPY
  SENTRY_PUBLIC_DSN: SENTRY_PUBLIC_DSN
  ARTWORK_EMBED_URL: ARTWORK_EMBED_URL
  GOOGLE_SEARCH_CX: GOOGLE_SEARCH_CX
  APPLICATION_NAME: APPLICATION_NAME
  EMBEDLY_KEY: EMBEDLY_KEY
  DISABLE_IMAGE_PROXY: DISABLE_IMAGE_PROXY
  SHOW_AUCTIONS_IN_HEADER: SHOW_AUCTIONS_IN_HEADER

CurrentUser = require '../models/current_user'

module.exports = (app) ->

  # Increase max sockets. The goal of this is to improve app -> api
  # performance but the downside is it limits client connection reuse with keep-alive
  if typeof MAX_SOCKETS == 'number' and MAX_SOCKETS > 0
    http.globalAgent.maxSockets = MAX_SOCKETS
  else
    http.globalAgent.maxSockets = Number.MAX_VALUE

  # Override Backbone to use server-side sync, inject the XAPP token,
  # add redis caching, and augment sync with Q promises.
  Backbone.sync = require "backbone-super-sync"
  Backbone.sync.editRequest = editRequest
  console.log 'CACHE', cache.client
  Backbone.sync.cacheClient = cache.client
  Backbone.sync.defaultCacheTime = DEFAULT_CACHE_TIME

  # Inject sharify data before anything
  app.use sharify

  # Development / Test only middlewares that compile assets, mount antigravity, and
  # allow a back door to log in for tests.
  if "development" is NODE_ENV
    app.use require("stylus").middleware
      src: path.resolve(__dirname, "../")
      dest: path.resolve(__dirname, "../public")
    app.use require("browserify-dev-middleware")
      src: path.resolve(__dirname, "../")
      transforms: [require("jadeify"), require('caching-coffeeify')]<commit_msg>remove log<commit_after>#
# Sets up intial project settings, middleware, mounted apps, and
# global configuration such as overriding Backbone.sync and
# populating sharify data
#

{ API_URL, NODE_ENV, ARTSY_ID, ARTSY_SECRET, SESSION_SECRET,
  SESSION_COOKIE_MAX_AGE, PORT, ASSET_PATH, FACEBOOK_APP_NAMESPACE,
  MOBILE_MEDIA_QUERY, MOBILE_URL, APP_URL, OPENREDIS_URL, DEFAULT_CACHE_TIME,
  CANONICAL_MOBILE_URL, IMAGES_URL_PREFIX, SECURE_IMAGES_URL,
  GOOGLE_ANALYTICS_ID, MIXPANEL_ID, SNOWPLOW_COLLECTOR_HOST, GOOGLE_SEARCH_CX,
  GOOGLE_SEARCH_KEY, COOKIE_DOMAIN, AUTO_GRAVITY_LOGIN, GOOGLE_MAPS_API_KEY,
  ADMIN_URL, CMS_URL, MAX_SOCKETS, ARTWORK_EMBED_URL, DELTA_HOST,
  ENABLE_AB_TEST, KIOSK_MODE, KIOSK_PAGE, SESSION_COOKIE_KEY, SENTRY_DSN,
  SENTRY_PUBLIC_DSN, SHOW_AUCTIONS_IN_HEADER, EMPTY_COLLECTION_SET_ID,
  GEMINI_S3_ACCESS_KEY, GEMINI_APP, GEMINI_ACCOUNT_KEY, BIDDER_H1_COPY,
  BIDDER_H2_COPY, APPLICATION_NAME, EMBEDLY_KEY, DISABLE_IMAGE_PROXY,
  POSITRON_URL } = config = require "../config"
{ parse, format } = require 'url'
_ = require 'underscore'
express = require "express"
Backbone = require "backbone"
sharify = require "sharify"
http = require 'http'
path = require "path"
artsyPassport = require 'artsy-passport'
artsyXappMiddlware = require 'artsy-xapp-middleware'
redirectMobile = require './middleware/redirect_mobile'
proxyGravity = require './middleware/proxy_to_gravity'
proxyReflection = require './middleware/proxy_to_reflection'
proxySitemaps = require './middleware/proxy_sitemaps'
localsMiddleware = require './middleware/locals'
micrositeMiddleware = require './middleware/microsite'
ensureSSL = require './middleware/ensure_ssl'
escapedFragmentMiddleware = require './middleware/escaped_fragment'
sameOriginMiddleware = require './middleware/same_origin'
hstsMiddleware = require './middleware/hsts'
unsupportedBrowserCheck = require "./middleware/unsupported_browser"
flash = require 'connect-flash'
flashMiddleware = require './middleware/flash'
bodyParser = require 'body-parser'
cookieParser = require 'cookie-parser'
session = require 'cookie-session'
favicon = require 'serve-favicon'
logger = require 'morgan'
editRequest = require './edit_request'
raven = require 'raven'
fs = require 'graceful-fs'
artsyError = require 'artsy-error-handler'
cache = require './cache'

# Setup sharify constants & require dependencies that use sharify data
sharify.data =
  JS_EXT: (if ("production" is NODE_ENV or "staging" is NODE_ENV) then ".min.js.cgz" else ".js")
  CSS_EXT: (if ("production" is NODE_ENV or "staging" is NODE_ENV) then ".min.css.cgz" else ".css")
  ASSET_PATH: ASSET_PATH
  APP_URL: APP_URL
  POSITRON_URL: POSITRON_URL
  API_URL: API_URL
  NODE_ENV: NODE_ENV
  MOBILE_MEDIA_QUERY: MOBILE_MEDIA_QUERY
  CANONICAL_MOBILE_URL: CANONICAL_MOBILE_URL
  MOBILE_URL: MOBILE_URL
  FACEBOOK_APP_NAMESPACE: FACEBOOK_APP_NAMESPACE
  SECURE_IMAGES_URL: SECURE_IMAGES_URL
  IMAGES_URL_PREFIX: IMAGES_URL_PREFIX
  GOOGLE_ANALYTICS_ID: GOOGLE_ANALYTICS_ID
  MIXPANEL_ID: MIXPANEL_ID
  SNOWPLOW_COLLECTOR_HOST: SNOWPLOW_COLLECTOR_HOST
  AUTO_GRAVITY_LOGIN: AUTO_GRAVITY_LOGIN
  GOOGLE_MAPS_API_KEY: GOOGLE_MAPS_API_KEY
  ADMIN_URL: ADMIN_URL
  CMS_URL: CMS_URL
  DELTA_HOST: DELTA_HOST
  ENABLE_AB_TEST: ENABLE_AB_TEST
  KIOSK_PAGE: KIOSK_PAGE
  KIOSK_MODE: KIOSK_MODE
  EMPTY_COLLECTION_SET_ID: EMPTY_COLLECTION_SET_ID
  GEMINI_S3_ACCESS_KEY: GEMINI_S3_ACCESS_KEY
  GEMINI_APP: GEMINI_APP
  GEMINI_ACCOUNT_KEY: GEMINI_ACCOUNT_KEY
  BIDDER_H1_COPY: BIDDER_H1_COPY
  BIDDER_H2_COPY: BIDDER_H2_COPY
  SENTRY_PUBLIC_DSN: SENTRY_PUBLIC_DSN
  ARTWORK_EMBED_URL: ARTWORK_EMBED_URL
  GOOGLE_SEARCH_CX: GOOGLE_SEARCH_CX
  APPLICATION_NAME: APPLICATION_NAME
  EMBEDLY_KEY: EMBEDLY_KEY
  DISABLE_IMAGE_PROXY: DISABLE_IMAGE_PROXY
  SHOW_AUCTIONS_IN_HEADER: SHOW_AUCTIONS_IN_HEADER

CurrentUser = require '../models/current_user'

module.exports = (app) ->

  # Increase max sockets. The goal of this is to improve app -> api
  # performance but the downside is it limits client connection reuse with keep-alive
  if typeof MAX_SOCKETS == 'number' and MAX_SOCKETS > 0
    http.globalAgent.maxSockets = MAX_SOCKETS
  else
    http.globalAgent.maxSockets = Number.MAX_VALUE

  # Override Backbone to use server-side sync, inject the XAPP token,
  # add redis caching, and augment sync with Q promises.
  Backbone.sync = require "backbone-super-sync"
  Backbone.sync.editRequest = editRequest
  Backbone.sync.cacheClient = cache.client
  Backbone.sync.defaultCacheTime = DEFAULT_CACHE_TIME

  # Inject sharify data before anything
  app.use sharify

  # Development / Test only middlewares that compile assets, mount antigravity, and
  # allow a back door to log in for tests.
  if "development" is NODE_ENV
    app.use require("stylus").middleware
      src: path.resolve(__dirname, "../")
      dest: path.resolve(__dirname, "../public")
    app.use require("browserify-dev-middleware")
      src: path.resolve(__dirname, "../")
      transforms: [require("jadeify"), require('caching-coffeeify')]
{'fraction_non_alphanumeric': 0.0819021145636851, 'fraction_numerical': 0.0019855058076044874, 'mean_word_length': 5.792987188132164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4963112', 'n_tokens_mistral': 3862, 'n_tokens_neox': 3699, 'n_words': 773}