summaryrefslogtreecommitdiff
path: root/examples/lib/okpush/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'examples/lib/okpush/index.js')
-rw-r--r--examples/lib/okpush/index.js45
1 files changed, 32 insertions, 13 deletions
diff --git a/examples/lib/okpush/index.js b/examples/lib/okpush/index.js
index d77eb8a..3ff8bb5 100644
--- a/examples/lib/okpush/index.js
+++ b/examples/lib/okpush/index.js
@@ -46,23 +46,42 @@ function OKPush (options) {
apn.init(config)
db.init(config)
-// router.use('/admin/', passport.initialize())
-// router.all('/admin/(:path*)?', passport.authenticate('digest', {
-// session: false
-// }))
+ router.use('/admin/', passport.initialize())
+ // monkeypatch because of this app.use(router) shit.. obnoxious
+ router.all('/admin/(:path*)?', function (req, res, next) {
+ // req.url = "/_services/push" + req.url
+ req.newUrl = req.url
+ req.url = req.originalUrl
+ next()
+ })
+ router.all('/admin/(:path*)?', passport.authenticate('digest', {
+ session: false
+ }))
+ router.all('/admin/(:path*)?', function (req, res, next) {
+ req.url = req.newUrl
+ next()
+ })
+
// 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('/admin', function (req, res) {
+ db.getNotifications(function(err, notes){
+ var data = {
+ meta: meta,
+ notifications: config.notifications,
+ }
+ notes.forEach(function(note){
+ if (note.key in data.notifications) {
+ data.notifications[ note.key ].last_push = note.last_push
+ }
+ })
+ templates['index'].render(data).then(function(rendered) {
+ res.send(rendered);
+ }).fail(error(req, res, 500))
+ })
})
- router.post('/send', function (req, res) {
+ router.post('/admin/send', function (req, res) {
var key = req.body.key
var opt = options.config.notifications[key]
var note = apn.buildPayload(opt, options.config.bundleId)