-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
75 lines (68 loc) · 2.04 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var express = require("express");
var app = express();
var port = process.env.PORT || 3001;
var router = express.Router();
var path = require('path');
var request = require('request');
var bodyParser = require('body-parser');
var videoIds = require("./views/videoIds.json");
//
// set the view engine to ejs
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'views')))
app.use(bodyParser.json());
app.use(bodyParser.urlencoded()); // get information from html forms
router.post("/subscribe",function(req,res){
console.log(req.body);
request.post(
// Google Form: eRiyaz email subscription list
'https://docs.google.com/forms/d/1TxAR8sIKykkmJzOWssqhyjjPQ7jQPx6ZfFBAGjgrCuk/formResponse',
{form:req.body},
function (error, response, body) {
if (!error && response.statusCode == 200) {
var json_resp = {"info":"Subscribed successfully."};
res.json(json_resp);
} else {
var json_resp = {};
res.statusCode = 400;
res.json(json_resp);
}
}
);
});
router.post("/register",function(req, res){
console.log(req.body);
request.post(
// Google Form: Learn to Sing (Web)
'https://docs.google.com/forms/d/1vr-vtuEDsbKB5H6mn-b6LAtTZe5PSEL3Mj2ZnrLeDMs/formResponse',
{form:req.body},
function (error, response, body) {
if (!error && response.statusCode == 200) {
var json_resp = {"info":"Thank you for registering. We will contact you in two days time."};
res.json(json_resp);
} else {
var json_resp = {};
res.statusCode = 400;
res.json(json_resp);
}
}
);
});
/*
router.get("/contact",function(req,res){
res.sendFile(path + "contact.html");
});
*/
// about page
app.get('/video/:id', function(req, res) {
// res.render('subscription');
var id = req.params.id;
res.render('video', {
videoUrl: videoIds[id],
desc: "desc-"+id
});
});
app.use("/",router);
var server = app.listen(port, function() {
console.log('App listening at http://%s:%s', server.address().address, server.address().port);
});