-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.js
More file actions
86 lines (63 loc) · 1.93 KB
/
Copy pathweb.js
File metadata and controls
86 lines (63 loc) · 1.93 KB
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
76
77
78
79
80
81
82
83
84
85
86
// web.js
var express = require("express");
var logfmt = require("logfmt");
var app = express();
var client = require('redis-url').connect(process.env.REDISTOGO_URL);
app.use(logfmt.requestLogger());
app.get('/', function(req, res){
res.sendFile("index.html",function(err){ // Transfer The File With COntent Type Text/HTML
if(err){
res.end("Sorry, Error.");
}else{
res.end(); // Send The Response
}
});
})
app.get('/set/:key/:value', function(req, res) {
var fieldname = 'resource';
console.log('Set Key: '+ req.param('key'));
client.hset(req.param('key'), req.param('value') , req.param('value'));
res.send(req.param('key')+" successfully set with value " + req.param('value'));
});
app.get('/get/:key', function(req, res) {
console.log('Get Key: '+ req.param('key'));
var vals = [];
client.hkeys(req.param('key'),
function (err, replies) {
if (err){
console.log(err);
}
else{
console.log(replies.length + " replies:\n");
replies.forEach(function (reply, i) {
vals.push(reply);
console.log(" " + i + ": " + reply);
});
res.send(vals);
// client.quit();
}
});
});
var port = Number(process.env.PORT || 5000);
app.listen(port, function() {
console.log("Listening on " + port);
});
//-----------------
//Socket Application
//-----------------
// var app = require('express')()
// , server = require('http').createServer(app)
// , io = require('socket.io').listen(server);
// var port = Number(process.env.PORT || 5000);
// server.listen(port, function() {
// console.log("Listening on " + port);
// });
// app.get('/', function (req, res) {
// res.sendfile(__dirname + '/index.html');
// });
// io.sockets.on('connection', function (socket) {
// socket.emit('news', { hello: 'world' });
// socket.on('my other event', function (data) {
// console.log(data);
// });
// });