// Setup
const util = require('util')
const Event = require('events').EventEmitter
const bodyParser = require('body-parser').json()
var app, logger

// Exports
module.exports = function (thisApp, channel) {
  if (typeof channel === 'string') {
    var channelName = channel.toString()
    channel = function () {}
    Object.defineProperty(channel, 'name', {
      configurable: true,
      enumerable: false,
      value: channelName,
      writable: false
    })
  }
  channel._channelName = channel.name
    .replace(/\.?([A-Z]+)/g, (x, y) => (' ' + y)).trim()
    .replace(/\s+/g, '_').toLowerCase()
  app = app || thisApp
  logger = logger || app.config.logger
  channel._ns = app._ns
  util.inherits(channel, Channel)
  Object.keys(Channel).map(function (e) { channel[e] = Channel[e] })
  return channel
}

function Channel () {}

util.inherits(Channel, Event)

/* CLASS METHODS */
// Return new channel
Channel.new = function () {
  var Class = this
  var channel = new Class()
  channel.channelName = Class._channelName
  channel._ns = Class._ns
  channel.http = app.server.http.express
  channel.initRoutes()
  return channel
}

/* INSTANCE METHODS */
// Initialize routes
Channel.prototype.initRoutes = function () {
  var self = this
  /* HTTP Routes */
  var channelRoot = '/' + self.channelName + '/'
  // VALIDATE
  // GET: /channel/_validate
  self.http.get(channelRoot + '_validate/', (req, res) => res.send(true))
  // SEARCH
  // GET: /channel
  self.http.get(channelRoot, function (req, res) {
    app.server.http.authenticate(req, res)
    req.once('authenticated', function (req, res) {
      return self.emit('route-search', req, res)
    })
  })
  // CREATE
  // POST: /channel
  self.http.post(channelRoot, bodyParser, function (req, res) {
    app.server.http.authenticate(req, res)
    req.once('authenticated', function (req, res) {
      Object.keys(req.body).map(function (k) { req.params[k] = req.body[k] })
      return self.emit('route-create', req, res)
    })
  })
  // READ
  // GET: /channel/:id
  self.http.get(channelRoot + ':id', function (req, res) {
    app.server.http.authenticate(req, res)
    req.once('authenticated', function (req, res) {
      return self.emit('route-read', req, res)
    })
  })
  // UPDATE
  // PUT: /channel/:id
  self.http.put(channelRoot + ':id', bodyParser, function (req, res) {
    app.server.http.authenticate(req, res)
    req.once('authenticated', function (req, res) {
      Object.keys(req.body).map(function (k) { req.params[k] = req.body[k] })
      return self.emit('route-update', req, res)
    })
  })
  // DELETE
  // DELETE: /channel/:id
  self.http.delete(channelRoot + ':id', function (req, res) {
    app.server.http.authenticate(req, res)
    req.once('authenticated', function (req, res) {
      return self.emit('route-delete', req, res)
    })
  })
}

@@ -923,28 +923,32 @@
 = function (
+opts
 ) %7B%0A
-
   var Class 
@@ -982,16 +982,144 @@
 Class()%0A
+  var skipAuth = %7B%7D%0A  if (opts && opts.skipAuth) opts.skipAuth.forEach((a) =%3E skipAuth%5Ba%5D = true)%0A  channel.skipAuth = skipAuth%0A
   channe
@@ -1630,32 +1630,105 @@
 on (req, res) %7B%0A
+    if (self.skipAuth.search) return self.emit('route-search', req, res)%0A
     app.server.h
@@ -1955,32 +1955,181 @@
 on (req, res) %7B%0A
+    Object.keys(req.body).map(function (k) %7B req.params%5Bk%5D = req.body%5Bk%5D %7D)%0A    if (self.skipAuth.create) return self.emit('route-create', req, res)%0A
     app.server.h
@@ -2211,86 +2211,8 @@
 ) %7B%0A
-      Object.keys(req.body).map(function (k) %7B req.params%5Bk%5D = req.body%5Bk%5D %7D)%0A
     
@@ -2352,32 +2352,101 @@
 on (req, res) %7B%0A
+    if (self.skipAuth.read) return self.emit('route-read', req, res)%0A
     app.server.h
@@ -2681,32 +2681,181 @@
 on (req, res) %7B%0A
+    Object.keys(req.body).map(function (k) %7B req.params%5Bk%5D = req.body%5Bk%5D %7D)%0A    if (self.skipAuth.update) return self.emit('route-update', req, res)%0A
     app.server.h
@@ -2937,86 +2937,8 @@
 ) %7B%0A
-      Object.keys(req.body).map(function (k) %7B req.params%5Bk%5D = req.body%5Bk%5D %7D)%0A
     
@@ -3024,32 +3024,32 @@
 E: /channel/:id%0A
-
   self.http.dele
@@ -3090,24 +3090,97 @@
 req, res) %7B%0A
+    if (self.skipAuth.delete) return self.emit('route-delete', req, res)%0A
     app.serv

Add skipAuth option to channels