diff options
Diffstat (limited to 'lib/okpush/index.js')
| -rw-r--r-- | lib/okpush/index.js | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/lib/okpush/index.js b/lib/okpush/index.js index df9c8265..6de59ac5 100644 --- a/lib/okpush/index.js +++ b/lib/okpush/index.js @@ -50,23 +50,23 @@ function OKPush (options) { apn.init(config) db.init(config) -// router.use('/admin/', passport.initialize()) + router.use('/admin/', passport.initialize()) router.use('/public/', express.static(path.join(__dirname, './public'))); // monkeypatch because of app.use(router) .. obnoxious -// router.all('/admin/(:path*)?', function (req, res, next) { -// console.log(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() -// }) + router.all('/admin/(:path*)?', function (req, res, next) { + console.log(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) { @@ -81,9 +81,9 @@ function OKPush (options) { if (note.key in data.notifications) { data.notifications[ note.key ].last_push = note.last_push } - if (note.key in count) { - data.notifications[ note.key ].count = count[note.key] - } + }) + Object.keys(count).forEach(function(key){ + data.notifications[ key ].count = count[key] }) templates['index'].render(data).then(function(rendered) { res.send(rendered); @@ -91,6 +91,12 @@ function OKPush (options) { }) }) }) + + router.get('/list', function(req, res){ + db.getAllTokens("hub", function(err, hubz){ + res.json(hubz) + }) + }) router.post('/send', bodyParser.urlencoded({ extended: false }), function (req, res) { var key = req.body.key @@ -103,18 +109,21 @@ function OKPush (options) { }) // should work without middleware - router.post('/add', function (req, res) { + router.post('/add', bodyParser.urlencoded({ extended: false }), function (req, res) { db.addToken({ token: req.body.registrationId, channel: req.body.channel, platform: req.body.platform, }) + res.sendStatus(200) }) - router.post('/remove', function (req, res) { + + router.post('/remove', bodyParser.urlencoded({ extended: false }), function (req, res) { db.removeToken({ token: req.body.registrationId, channel: req.body.channel, }) + res.sendStatus(200) }) this._router = router |
