const events = ev.events;
var timer = null;
+/* Disables caching in client */
+function nocache(req, res, next) {
+ res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
+ res.header('Expires', '-1');
+ res.header('Pragma', 'no-cache');
+ next();
+}
+
/* POST /vN/test/control */
-router.post('/', function(req, res, next) {
+router.post('/', nocache, function(req, res, next) {
// check header
if (typeof req.header('X-API-Key-Test') === 'undefined') {
log.info('API key not set in request header');
log.debug('Timeout, no events');
clearTimeout(timer);
timer = null;
-//console.log('response:', response);
response.status(304).end('');
response = null;
}
const router = express.Router();
const dblib = require('./../../../lib/dblib');
+/* Disables caching in client */
+function nocache(req, res, next) {
+ res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
+ res.header('Expires', '-1');
+ res.header('Pragma', 'no-cache');
+ next();
+}
+
/* POST /vN/test/notification */
-router.post('/', function(req, res, next) {
+router.post('/', nocache, function(req, res, next) {
// check header
if (typeof req.header('X-API-Key-Test') === 'undefined') {
log.info('API key not set in request header');
const qStr = require('query-string');
const router = express.Router();
const dblib = require('./../../../lib/dblib');
+const fs = require('fs');
const webpush = require('web-push');
const delayMin = -1;
log.debug('Notification set to execute in ' + delay + ' seconds');
}
-/*
-{
- "endpoint":"https://fcm.googleapis.com/fcm/send/eGS6ZOFQcUk:APA91bGZliEmCLdFcuytpz2KFdLZVNm4YwAdbjaRxyF8tl6vhmuNd7L0NZagys77AjA3GWc3RNhad3i3Bc3rwBQEPKfAX4LZ0jOPzo_heG-WL7MNZx5w9lI2qycrdNk8UiQS0IlhL-j5",
- "expirationTime":null,
- "keys":{
- "p256dh":"BAMu7XxsCuoB0j1zdaNGXoRterzytIpyG7yxzfEnAaA0SF4xTWJOztnbUoKX4IBdKpteJA9UhhyLI286mZKUlTQ",
- "auth":"iPebCb94XG_zeVdfAmKN8Q"
- }
-}
-*/
function executeNotification(notification) {
clearTimeout(timer);
timer = null;
// web push
- webpush.setGCMAPIKey('AAAAUtHuYco:APA91bEBTxCRGaez9_glljXAlit3PY5HMwhLSqWYMC1j-jFSp6nvnNqjI42jAVFApQbM0oyAOQjCUilIovB76cwTFxyZTP96wm9n09XwiMRXJjhwiJX1hO32mBB2zwK6X-w7epE1V67K');
+ webpush.setGCMAPIKey('AAAAUtHuYco:APA91bEBTxCRGaez9_glljXAlit3PY5HMwhLSqWYMC1j-jFSp6nvnNqj' +
+ 'I42jAVFApQbM0oyAOQjCUilIovB76cwTFxyZTP96wm9n09XwiMRXJjhwiJX1hO32mBB2zwK6X-w7epE1V67K');
webpush.setVapidDetails(
'mailto:ebelcrom@gmail.com',
'BLDSdGasI5sLks30brbIWvlLMFqzoxxkOs7aW_E9PDBzIO_mDs6-tvtb2U0-BVFDafNd58DJgoXxdK5711FF29c',
p256dh: notification.keys.p256dh
}
};
- const options = {
- actions: [
- {
- action: 'Open Garage Node',
- title: 'Garage Node'
- }
- ],
- body: 'The garage door is open!',
- badge: './img/icons/android-chrome-192x192.png',
- icon: './img/icons/android-chrome-192x192.png'
+
+ const icon = 'data:image/png;base64,' +
+ fs.readFileSync(__dirname + '/../../../public/images/icon.png', 'base64');
+ const payload = {
+ message: 'The garage door is open!',
+ icon: icon
};
+ log.debug('Paylod length:', JSON.stringify(payload).length);
- webpush.sendNotification(pushSubscription, 'The garage door is open!')
+ webpush.sendNotification(pushSubscription, JSON.stringify(payload))
.then(data => {
if (data) {
log.info('sent, data:', JSON.stringify(data));
const dblib = require('./../../../lib/dblib');
const fs = require('fs');
+/* Disables caching in client */
+function nocache(req, res, next) {
+ res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
+ res.header('Expires', '-1');
+ res.header('Pragma', 'no-cache');
+ next();
+}
+
/* GET /vN/status */
-router.get('/', function(req, res, next) {
+router.get('/', nocache, function(req, res, next) {
// check header
if (typeof req.header('X-API-Key-Test') === 'undefined') {
log.info('API key not set in request header');