diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-10-05 17:49:19 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-10-05 17:49:19 -0400 |
| commit | ae843591da0fea1a57684f26737be0b484718809 (patch) | |
| tree | 547be3ae5d69c3568626a2f9ce9f35e034c82ed6 /examples/lib/okpush/index.js | |
| parent | 95df0e83fdb7f564d64b6c916e674e0db46c116d (diff) | |
okpush template stuff
Diffstat (limited to 'examples/lib/okpush/index.js')
| -rw-r--r-- | examples/lib/okpush/index.js | 62 |
1 files changed, 53 insertions, 9 deletions
diff --git a/examples/lib/okpush/index.js b/examples/lib/okpush/index.js index 8b10918..e8b6549 100644 --- a/examples/lib/okpush/index.js +++ b/examples/lib/okpush/index.js @@ -1,27 +1,71 @@ /** */ -var apn = require('apn'); +var OKTemplate = require('../../../app/node_modules/oktemplate') +var passport = require('passport') +var apn = require('./apn') +var db = require('./db') + +passport.use(new DigestStrategy({qop: 'auth'}, + function authenticate(username, done) { + if (!process.env.OK_USER || !process.env.OK_PASS) { + return done(new Error('No user or pass configured on server')) + } else { + return done(null, process.env.OK_USER, process.env.OK_PASS) + } +})) function OKPush (options) { if (!(this instanceof OKPush)) return new OKPush(options) options = options || {} if (!options.express) - throw new Error('Express not provided to OKPush'); + throw new Error('Express not provided to OKPush') if (!options.config) - throw new Error('Configuration not provided to OKPush'); - + throw new Error('Configuration not provided to OKPush') + if (!options.config.notifications) + throw new Error('Notifications not defined in OKPush') + var express = options.express var router = express.Router() var config = options.config - var db = options.db + var meta = options.meta + var error = options.errorHandler + // var okcms_db = options.db + + var templateProvider = this._templateProvider = new OKTemplate({ + root: path.join(__dirname, './templates'), + debug: meta.debug + }) + + var templates = {} + templates['index'] = templateProvider.getTemplate('index') + + apn.init() + db.init() + + router.use('/admin/', passport.initialize()) + router.all('/admin/(:path*)?', passport.authenticate('digest', { + session: false + })) + + // pass in admin middleware! + router.get('/admin/', function (req, res) { + var data = { + meta: meta, + notifications: config.notifications, + } + templates['index'].render(data).then(function(rendered) { + res.send(rendered); + }).fail(error(req, res, 500)) + }) - router.get('*', function (req, res) { - res.send(config.stuff) + router.post('/send', function (req, res) { + // add a key }) - router.post('*', function (req, res) { - throw new Error('OKPush POST requests not implemented') + // should work without middleware + router.post('/add', function (req, res) { + // add a key }) this._router = router |
