-
-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77ddafe
commit 522e66c
Showing
6 changed files
with
169 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "demo", | ||
"description": "Demo - progress web application", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"body-parser": "^1.15.0", | ||
"express": "^4.13.4", | ||
"node-gcm": "^0.14.0" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
"start": "node server.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
var express = require("express"); | ||
var bodyParser = require("body-parser"); | ||
var gcm = require('node-gcm'); | ||
var app = express(); | ||
|
||
//Here we are configuring express to use body-parser as middle-ware. | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(bodyParser.json()); | ||
|
||
//To server static assests in root dir | ||
app.use(express.static(__dirname)); | ||
|
||
//To allow cross origin request | ||
app.use(function(req, res, next) { | ||
res.header("Access-Control-Allow-Origin", "*"); | ||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | ||
next(); | ||
}); | ||
|
||
//To server index.html page | ||
app.get("/", function (req, res) { | ||
res.sendFile(__dirname + "/index.html"); | ||
}); | ||
|
||
//To receive push request from client | ||
app.post("/send_notification", function (req, res) { | ||
if (!req.body) { | ||
res.status(400); | ||
} | ||
|
||
var message = new gcm.Message(); | ||
var temp = req.body.endpoint.split("/"); | ||
var regTokens = [temp[temp.length - 1]]; | ||
|
||
var sender = new gcm.Sender('AIzaSyCjrU5SqotSg2ybDLK_7rMMt9Rv0dMusvY'); //API Key | ||
|
||
// Now the sender can be used to send messages | ||
sender.send(message, { registrationTokens: regTokens }, function (error, response) { | ||
if (error) { | ||
console.error(error); | ||
res.status(400); | ||
} | ||
else { | ||
console.log(response); | ||
res.status(200); | ||
} | ||
}); | ||
}); | ||
|
||
app.listen(3000, function() { | ||
console.log("Local Server : http://localhost:3000"); | ||
}); |
Oops, something went wrong.