/* eslint spaced-comment:0 */

/**
 * HTTP Server Settings
 * (sails.config.http)
 *
 * Configuration for the underlying HTTP server in Sails.
 * Only applies to HTTP requests (not WebSockets)
 *
 * For more information on configuration, check out:
 * http://sailsjs.org/#/documentation/reference/sails.config/sails.config.http.html
 */

require('colors')
import util from 'util'
import kue from 'kue'
import kueUI from 'kue-ui'
import isAdmin from '../api/policies/isAdmin'
import { createRequestHandler } from '../api/graphql'

function customMiddleware (app) {
  kueUI.setup({
    apiURL: '/admin/kue/api',
    baseURL: '/admin/kue'
  })

  app.use('/admin/kue', isAdmin)
  app.use('/admin/kue/api', kue.app)
  app.use('/admin/kue', kueUI.app)
  app.use('/noo/graphql', createRequestHandler())
}

module.exports.http = {
  customMiddleware,

  /****************************************************************************
  *                                                                           *
  * Express middleware to use for every Sails request. To add custom          *
  * middleware to the mix, add a function to the middleware config object and *
  * add its key to the "order" array. The $custom key is reserved for         *
  * backwards-compatibility with Sails v0.9.x apps that use the               *
  * `customMiddleware` config option.                                         *
  *                                                                           *
  ****************************************************************************/
  middleware: {
    passportInit: require('passport').initialize(),
    passportSession: require('passport').session(),
    opbeat: require('opbeat').middleware.express(),
    rollbar: require('rollbar').errorHandler(process.env.ROLLBAR_SERVER_TOKEN),

    requestLogger: function (req, res, next) {
      sails.log.info(util.format('%s %s ', req.method, req.url).magenta)
      next()
    },

  /***************************************************************************
  *                                                                          *
  * The order in which middleware should be run for HTTP request. (the Sails *
  * router is invoked by the "router" middleware below.)                     *
  *                                                                          *
  ***************************************************************************/
    order: [
      'startRequestTimer',
      'cookieParser',
      'session',
      'passportInit',
      'passportSession',
      'bodyParser',
      'handleBodyParserError',
      'compress',
      'methodOverride',
      'poweredBy',
      'requestLogger',
      '$custom',
      'router',
      'www',
      'favicon',
      '404',
      'opbeat',
      'rollbar',
      '500'
    ]

  /***************************************************************************
  *                                                                          *
  * The body parser that will handle incoming multipart HTTP requests. By    *
  * default as of v0.10, Sails uses                                          *
  * [skipper](http://github.com/balderdashy/skipper). See                    *
  * http://www.senchalabs.org/connect/multipart.html for other options.      *
  *                                                                          *
  ***************************************************************************/
    // bodyParser: require('skipper')

  }

  /***************************************************************************
  *                                                                          *
  * The number of seconds to cache flat files on disk being served by        *
  * Express static middleware (by default, these files are in `.tmp/public`) *
  *                                                                          *
  * The HTTP static cache is only active in a 'production' environment,      *
  * since that's the only time Express will cache flat-files.                *
  *                                                                          *
  ***************************************************************************/
  // cache: 31557600000
}

@@ -335,468 +335,108 @@
 */%0A%0A
-require('colors')%0Aimport util from 'util'%0Aimport kue from 'kue'%0Aimport kueUI from 'kue-ui'%0Aimport isAdmin from '../api/policies/isAdmin'%0Aimport %7B createRequestHandler %7D from '../api/graphql'%0A%0Afunction customMiddleware (app) %7B%0A  kueUI.setup(%7B%0A    apiURL: '/admin/kue/api',%0A    baseURL: '/admin/kue'%0A  %7D)%0A%0A  app.use('/admin/kue', isAdmin)%0A  app.use('/admin/kue/api', kue.app)%0A  app.use('/admin/kue', kueUI.app)%0A  app.use('/noo/graphql', createRequestHandler())%0A%7D
+import %7B createRequestHandler %7D from '../api/graphql'%0Arequire('colors')%0Aconst util = require('util')
 %0A%0Amo
@@ -460,28 +460,8 @@
  = %7B
-%0A  customMiddleware,
 %0A%0A  
@@ -1178,16 +1178,17 @@
 ******/%0A
+%0A
   middle
@@ -1195,16 +1195,17 @@
 ware: %7B%0A
+%0A
     pass
@@ -2044,24 +2044,25 @@
 **********/%0A
+%0A
     order: %5B
@@ -3070,16 +3070,17 @@
 ******/%0A
+%0A
     // b
@@ -3110,16 +3110,425 @@
 pper')%0A%0A
+  %7D,%0A%0A  customMiddleware: function (app) %7B%0A    var kue = require('kue')%0A    var kueUI = require('kue-ui')%0A    var isAdmin = require('../api/policies/isAdmin')%0A%0A    kueUI.setup(%7B%0A      apiURL: '/admin/kue/api',%0A      baseURL: '/admin/kue'%0A    %7D)%0A%0A    app.use('/admin/kue', isAdmin)%0A    app.use('/admin/kue/api', kue.app)%0A    app.use('/admin/kue', kueUI.app)%0A    app.use('/noo/graphql', createRequestHandler())%0A
   %7D%0A%0A  /
@@ -4235,16 +4235,17 @@
 ******/%0A
+%0A
   // cac

revert unnecessary changes to config/http.js