Skip to content

Commit

Permalink
docs: fix minor error in vote examples
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Aug 14, 2020
1 parent 6f7f18d commit dd2caf5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
38 changes: 19 additions & 19 deletions examples/vote-helm/result-image/server.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
var express = require('express'),
async = require('async'),
path = require("path")
pg = require("pg"),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
app = express(),
server = require('http').Server(app),
io = require('socket.io')(server);
// io = require('socket.io')(server, { path: "/result/views/socket.io" });
async = require('async'),
path = require("path")
pg = require("pg"),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
app = express(),
server = require('http').Server(app),
io = require('socket.io')(server);
// io = require('socket.io')(server, { path: "/result/views/socket.io" });

io.set('transports', ['polling']);

var port = process.env.PORT || 4000;

io.sockets.on('connection', function (socket) {

socket.emit('message', { text : 'Welcome!' });
socket.emit('message', { text: 'Welcome!' });

socket.on('subscribe', function (data) {
socket.join(data.channel);
});
});

async.retry(
{times: 1000, interval: 1000},
function(callback) {
{ times: 1000, interval: 1000 },
function (callback) {
pg.connect('postgres://postgres:postgres@postgres/postgres', function (err, client, done) {
if (err) {
console.error("Waiting for db");
}
callback(err, client);
});
},
function(err, client) {
function (err, client) {
if (err) {
return console.err("Giving up");
return console.error("Giving up");
}
console.log("Connected to db");
getVotes(client);
}
);

function getVotes(client) {
client.query('SELECT vote, COUNT(id) AS count FROM votes GROUP BY vote', [], function(err, result) {
client.query('SELECT vote, COUNT(id) AS count FROM votes GROUP BY vote', [], function (err, result) {
if (err) {
console.error("Error performing query: " + err);
} else {
var votes = collectVotesFromResult(result);
io.sockets.emit("scores", JSON.stringify(votes));
}

setTimeout(function() {getVotes(client) }, 1000);
setTimeout(function () { getVotes(client) }, 1000);
});
}

function collectVotesFromResult(result) {
var votes = {a: 0, b: 0};
var votes = { a: 0, b: 0 };

result.rows.forEach(function (row) {
votes[row.vote] = parseInt(row.count);
Expand All @@ -68,7 +68,7 @@ function collectVotesFromResult(result) {
app.use(cookieParser());
app.use(bodyParser());
app.use(methodOverride('X-HTTP-Method-Override'));
app.use(function(req, res, next) {
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");
res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
Expand Down
2 changes: 1 addition & 1 deletion examples/vote/result/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async.retry(
},
function (err, client) {
if (err) {
return console.err("Giving up");
return console.error("Giving up");
}
console.log("Connected to db");
getVotes(client);
Expand Down

0 comments on commit dd2caf5

Please sign in to comment.