GithubHelp home page GithubHelp logo

jonatansalas / pushnotifications-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microsoftedge/pushnotifications-demo

0.0 2.0 0.0 5.73 MB

Demo for cross browsers push notifications with server side code

License: Apache License 2.0

JavaScript 38.11% PowerShell 0.16% HTML 38.01% CSS 23.72%

pushnotifications-demo's Introduction

Web Push Notifications Tutorial

This is a tutorial and demo for web push notifications that work in modern web browsers.

How to use

First, install all Node.js dependencies via npm install.

Note: You will need the necessary tools to compile binaries for node. If you are on a Windows platform the easiest way is to use the windows-build-tools package.

This demo requires access to a mongodb instance for storing push subscription info to send push updates at some other point in time. It also requires specifying a public and private key for identifying your server to the push service's server. These keys, known as VAPID public/private keys, can be generated and printed to the console when first executing the site. The site can be executed by running node index.js which will start a server on port 4000. You'll need to populate those keys as environment variables and execute node index.js again to ensure that push messages can be configured from your server.

If you are using VS Code you can set the environment variables mentioned above in your launch.json file as follows:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch demo",
            "program": "${workspaceFolder}/index.js",
            "env": {
                "DATABASE_CONNECTION_URI": "YOUR CONNECTION STRING",
                "VAPID_PUBLIC_KEY": "YOUR PUBLIC KEY",
                "VAPID_PRIVATE_KEY": "YOUR PRIVATE KEY",
            }
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Job",
            "program": "${workspaceFolder}/App_data/jobs/triggered/notify/index.js",
            "cwd": "${workspaceFolder}/App_data/jobs/triggered/notify",
            "env": {
                "DATABASE_CONNECTION_URI": "YOUR CONNECTION STRING",
                "VAPID_PUBLIC_KEY": "YOUR PUBLIC KEY",
                "VAPID_PRIVATE_KEY": "YOUR PRIVATE KEY",
            }
        }
    ]
}

Alternatively, you can modify configured-web-push.js and db/db.js and set the values there explicitly:

const databaseConnectionURI = process.env.DATABASE_CONNECTION_URI || '';
const vapidPublicKey = process.env.VAPID_PUBLIC_KEY || '';
const vapidPrivateKey = process.env.VAPID_PRIVATE_KEY || '';

pushnotifications-demo's People

Contributors

ststimac avatar aliams avatar molant avatar donmccurdy avatar

Watchers

James Cloos avatar Jonatan E. Salas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.