How to use the web-push.generateVAPIDKeys function in web-push

To help you get started, we’ve selected a few web-push examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / serviceworker-cookbook / push-rich / server.js View on Github external
// Use the web-push library to hide the implementation details of the communication
// between the application server and the push service.
// For details, see https://tools.ietf.org/html/draft-ietf-webpush-protocol and
// https://tools.ietf.org/html/draft-ietf-webpush-encryption.
const webPush = require('web-push');

if (!process.env.VAPID_PUBLIC_KEY || !process.env.VAPID_PRIVATE_KEY) {
  console.log("You must set the VAPID_PUBLIC_KEY and VAPID_PRIVATE_KEY "+
    "environment variables. You can use the following ones:");
  console.log(webPush.generateVAPIDKeys());
  return;
}
// Set the keys used for encrypting the push messages.
webPush.setVapidDetails(
  'https://serviceworke.rs/',
  process.env.VAPID_PUBLIC_KEY,
  process.env.VAPID_PRIVATE_KEY
);

module.exports = function(app, route) {
  app.get(route + 'vapidPublicKey', function(req, res) {
    res.send(process.env.VAPID_PUBLIC_KEY);
  });

  app.post(route + 'register', function(req, res) {
    // A real world application would store the subscription info.
github mozilla / serviceworker-cookbook / push-quota / server.js View on Github external
// Use the web-push library to hide the implementation details of the communication
// between the application server and the push service.
// For details, see https://tools.ietf.org/html/draft-ietf-webpush-protocol and
// https://tools.ietf.org/html/draft-ietf-webpush-encryption.
const webPush = require('web-push');

if (!process.env.VAPID_PUBLIC_KEY || !process.env.VAPID_PRIVATE_KEY) {
  console.log("You must set the VAPID_PUBLIC_KEY and VAPID_PRIVATE_KEY "+
    "environment variables. You can use the following ones:");
  console.log(webPush.generateVAPIDKeys());
  return;
}
// Set the keys used for encrypting the push messages.
webPush.setVapidDetails(
  'https://serviceworke.rs/',
  process.env.VAPID_PUBLIC_KEY,
  process.env.VAPID_PRIVATE_KEY
);

module.exports = function(app, route) {
  app.get(route + 'vapidPublicKey', function(req, res) {
    res.send(process.env.VAPID_PUBLIC_KEY);
  });

  app.post(route + 'register', function(req, res) {
    // A real world application would store the subscription info.
github mozilla / serviceworker-cookbook / push-clients / server.js View on Github external
// Use the web-push library to hide the implementation details of the communication
// between the application server and the push service.
// For details, see https://tools.ietf.org/html/draft-ietf-webpush-protocol and
// https://tools.ietf.org/html/draft-ietf-webpush-encryption.
const webPush = require('web-push');

if (!process.env.VAPID_PUBLIC_KEY || !process.env.VAPID_PRIVATE_KEY) {
  console.log("You must set the VAPID_PUBLIC_KEY and VAPID_PRIVATE_KEY "+
    "environment variables. You can use the following ones:");
  console.log(webPush.generateVAPIDKeys());
  return;
}
// Set the keys used for encrypting the push messages.
webPush.setVapidDetails(
  'https://serviceworke.rs/',
  process.env.VAPID_PUBLIC_KEY,
  process.env.VAPID_PRIVATE_KEY
);

module.exports = function(app, route) {
  app.get(route + 'vapidPublicKey', function(req, res) {
    res.send(process.env.VAPID_PUBLIC_KEY);
  });

  app.post(route + 'register', function(req, res) {
    // A real world application would store the subscription info.
github lowercasename / sweet / server.js View on Github external
secret: auth.secret
  })
}));
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
app.use(function (req, res, next) {
  res.locals.sessionFlash = req.session.sessionFlash;
  delete req.session.sessionFlash;
  next();
});

//set up webpush to send push notifications for the notifier
webpush = require('web-push');
if (!auth.vapidPrivateKey || !auth.vapidPublicKey) {
  vapidKeys = webpush.generateVAPIDKeys();
  webpush.setVapidDetails(
    'mailto:support@sweet.sh',
    vapidKeys.publicKey,
    vapidKeys.privateKey
  );
} else {
  webpush.setVapidDetails(
    'mailto:support@sweet.sh',
    auth.vapidPublicKey,
    auth.vapidPrivateKey
  );
}

//kill the process when the sigint code is recieved, generally generated by pressing ctrl-c in the console
app.on('SIGINT', function () {
  db.stop(function (err) {
github GoogleChromeLabs / web-push-testing-service / test / get-test-subscription.js View on Github external
*     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
**/
'use strict';

const fetch = require('node-fetch');
const webPush = require('web-push');

require('chai').should();

const VAPID_KEYS = webPush.generateVAPIDKeys();

const GCM_DETAILS = {
  senderId: '914034011562',
  apiKey: 'AIzaSyBSBJfbEP3Upq-fkuDVDep9YgNUGHymKxs',
};

describe('Test get-subscription API', function() {
  this.retries(2);

  const WPTS = require('../src/index.js');

  const globalWPTS = new WPTS(8090);

  const browserVariants = [
    {
      browser: 'chrome',
github lunchclass / absolute / server / push / gen_push_key.js View on Github external
export default function generatePushKey() {
  if(pushKeys.pushVapidKeys.privateKey === undefined
    || pushKeys.pushVapidKeys.privateKey === '') {
    console.log('generate push key');
    const vapidKeys = webpush.generateVAPIDKeys();
    pushKeys.pushVapidKeys.privateKey = vapidKeys.privateKey;
    pushKeys.pushVapidKeys.publicKey = vapidKeys.publicKey;

    writeClientPushPubkey(vapidKeys.publicKey);
    writeServerPusKey(pushKeys);
  }
}
github Canop / miaou / libs / web-push.js View on Github external
exports.configure = function(_miaou){
	miaou = _miaou;
	vapid = miaou.conf("web-push", "VAPID") || {};
	if (!vapid.publicKey || !vapid.privateKey) {
		console.log("You must set the VAPID keys in Miaou config. You can use the following ones:");
		console.log(webPush.generateVAPIDKeys());
		return;
	}
	let email = miaou.conf("admin-email");
	if (!email) {
		console.log("admin-email must be set in Miaou config");
		return;
	}
	webPush.setVapidDetails(
		"mailto:"+email,
		vapid.publicKey,
		vapid.privateKey
	);
	return this;
}
github HermesMessenger / Hermes / src / server / utils / config.ts View on Github external
webPush: VapidKeys;
  db: DB;
}

interface DB {
  hosts: string[];
  keyspace: string;
  username: string;
  password: string;
  datacenter: string;
}

export const template: Config = {
  mainIP: 'localhost',
  port: 8080,
  webPush: generateVAPIDKeys(),
  db: {
    hosts: ['127.0.0.1'],
    keyspace: 'hermes',
    username: 'cassandra',
    password: 'cassandra',
    datacenter: 'datacenter1'
  }
}

const file = path.resolve(__dirname, '../../../config.json')
const contents = fs.readFileSync(file, 'utf8')

export const config = JSON.parse(contents) as Config
github shadowsocks / shadowsocks-manager / lib / plugins / webgui / server / push.js View on Github external
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

const webpush = require('web-push');
const vapidKeys = webpush.generateVAPIDKeys();
const knex = appRequire('init/knex').knex;
const config = appRequire('services/config').all();

webpush.setGCMAPIKey(config.plugins.webgui.gcmAPIKey);
webpush.setVapidDetails('mailto:xxx@ooo.com', vapidKeys.publicKey, vapidKeys.privateKey);

exports.pushMessage = (() => {
  var _ref = _asyncToGenerator(function* (title, options) {
    const users = yield knex('push').select();
    const arr = [];
    users.forEach(function (user) {
      const promise = webpush.sendNotification({
        endpoint: user.endpoint,
        keys: {
          auth: user.auth,
          p256dh: user.p256dh
github Soluto / tweek / services / editor / server / getVapidKeys.js View on Github external
export default async function getKeys() {
  if (vapidKeys) return vapidKeys;

  const VAPID_KEYS = nconf.get('VAPID_KEYS');

  if (!fs.existsSync(VAPID_KEYS)) {
    vapidKeys = webPush.generateVAPIDKeys();
    await writeFile(VAPID_KEYS, JSON.stringify(vapidKeys));
    return vapidKeys;
  }

  const keysStr = await readFile(VAPID_KEYS);
  vapidKeys = JSON.parse(keysStr);
  return vapidKeys;
}

web-push

Web Push library for Node.js

MPL-2.0
Latest version published 4 months ago

Package Health Score

80 / 100
Full package analysis