From dd2caf511ee7317191e0e2ff05d34347ce4e9a85 Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Tue, 11 Aug 2020 10:52:26 +0200 Subject: [PATCH] docs: fix minor error in vote examples --- examples/vote-helm/result-image/server.js | 38 +++++++++++------------ examples/vote/result/server.js | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/vote-helm/result-image/server.js b/examples/vote-helm/result-image/server.js index b67df797af..78fdf64649 100644 --- a/examples/vote-helm/result-image/server.js +++ b/examples/vote-helm/result-image/server.js @@ -1,14 +1,14 @@ 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']); @@ -16,7 +16,7 @@ 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); @@ -24,8 +24,8 @@ io.sockets.on('connection', function (socket) { }); 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"); @@ -33,9 +33,9 @@ async.retry( 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); @@ -43,7 +43,7 @@ async.retry( ); 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 { @@ -51,12 +51,12 @@ function getVotes(client) { 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); @@ -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"); diff --git a/examples/vote/result/server.js b/examples/vote/result/server.js index ae397d1593..3066009c49 100644 --- a/examples/vote/result/server.js +++ b/examples/vote/result/server.js @@ -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);