var express=require('express');
var webpush=require('web-push');
var path=require('path');

var app=express();

app.use(express.static(path.join(__dirname,'node-push-notifications-client')));

var bodyParser=require('body-parser');

//var urlencodedParser=bodyParser.urlencoded({extended: true});

app.use(bodyParser.urlencoded({
    extended: true
}));
app.use(bodyParser.json());

const publicKey='<KEY>';
const privateKey='<KEY>';

webpush.setVapidDetails('mailto:<EMAIL>',publicKey,privateKey);

app.post('/subscribe',function(req,res){
   
    console.log('came here');
    console.log(req.body)
	const subscription=req.body;
	res.status(201).json({});
	const payload=JSON.stringify({title:'Push Test'});
	webpush.sendNotification(subscription,payload).catch(function(err){
        console.log('yh h kya error');
	 });
});

app.listen('8080');