diff options
| author | Sean Fridman <fridman@mail.sfsu.edu> | 2015-04-08 19:55:34 -0400 |
|---|---|---|
| committer | Sean Fridman <fridman@mail.sfsu.edu> | 2015-04-08 19:55:34 -0400 |
| commit | 32f87fcb58466e0e311349f96751c18e2a2cd7ea (patch) | |
| tree | 9b8c5e37821e147048e5d1ddbe5435af47716949 /app/index.js | |
| parent | 51296eb133599d98dd05d04399898c42b1662ab5 (diff) | |
Administrate!
Diffstat (limited to 'app/index.js')
| -rw-r--r-- | app/index.js | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/app/index.js b/app/index.js index 94d87dc..4ec8730 100644 --- a/app/index.js +++ b/app/index.js @@ -7,6 +7,7 @@ var express = require('express'); var Q = require('q'); var OKQuery = require('okquery'); var OKView = require('okview'); +var OKAdminView = require('okadminview'); var OKDB = require('okdb'); var OKResource = require('okresource') var OKTemplate = require('oktemplate'); @@ -80,11 +81,16 @@ function OKCMS(options) { // Create view instances from config var views = this._views = this._createViews(viewConfig, db, meta, resourceCache, templateProvider); + var adminViews = this._adminViews = + this._createAdminViews(adminPath, app, express, resourceConfig, + resourceCache, adminTemplateProvider, adminMeta); var server = this._server = new OKServer({ express: express, app: app, - views: views, + // Merge admin views with normal views + views: assign(views, adminViews), + // Specify root folders and paths for serving static assets root: root, adminRoot: adminRoot, adminPath: adminPath @@ -166,7 +172,37 @@ OKCMS.prototype._createViews = function(viewConfig, db, else return '404'; } -} +}; + +OKCMS.prototype._createAdminViews = function(path, app, express, + resourceConfig, resourceCache, templateProvider, meta) { + var views = {}; + var withTrail = withTrailingSlash(path); + var withoutTrail = withoutTrailingSlash(path); + // Stoopid fix for a bug in Express. Need to do this + // to ensure strict routing is not broken for the nested + // admin router. + // See: https://github.com/strongloop/express/issues/2281 + // TODO Get rid of this crap + views[withoutTrail] = { + mount: 'get', + middleware: function() { + return function(req, res) { + res.redirect(301, withTrail); + } + } + }; + // Add real view at trailing slash route + views[withTrail] = OKAdminView({ + app: app, + express: express, + resourceConfig: resourceConfig, + resourceCache: resourceCache, + templateProvider: templateProvider, + meta: meta + }); + return views; +}; OKCMS.prototype._createQueries = function(queryConfig, resourceCache) { queryConfig = queryConfig || {}; @@ -218,7 +254,7 @@ ResourceCache.prototype.get = function(type, id) { module.exports = { createApp: function(options) { - return new OKCMS(options); + return OKCMS(options); }, OKResource: OKResource, |
