Skip to content

Commit

Permalink
Switched from JSHint to Semistandard and upgraded dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed May 23, 2016
1 parent f5c0f0e commit d8d4589
Show file tree
Hide file tree
Showing 98 changed files with 675 additions and 774 deletions.
12 changes: 2 additions & 10 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
appengine/bower/public/bower_components/**
appengine/kraken/public/components/**
appengine/parse-server/cloud/main.js
appengine/sails/config/**
appengine/sails/tasks/**
appengine/sails/assets/**
appengine/sails/api/responses/**
appengine/webpack/dist/**

functions/**
**/node_modules/**
coverage/

logging/fluent.js
15 changes: 7 additions & 8 deletions appengine/analytics/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var app = express();
// but will need to be manually set when running locally. See README.md.
var GA_TRACKING_ID = process.env.GA_TRACKING_ID;

function trackEvent(category, action, label, value, cb) {
function trackEvent (category, action, label, value, cb) {
var data = {
v: '1', // API Version.
tid: GA_TRACKING_ID, // Tracking ID / Property ID.
Expand All @@ -35,14 +35,14 @@ function trackEvent(category, action, label, value, cb) {
ec: category, // Event category.
ea: action, // Event action.
el: label, // Event label.
ev: value, // Event value.
ev: value // Event value.
};

request.post(
'http://www.google-analytics.com/collect', {
form: data
},
function(err, response) {
function (err, response) {
if (err) { return cb(err); }
if (response.statusCode !== 200) {
return cb(new Error('Tracking failed'));
Expand All @@ -52,13 +52,13 @@ function trackEvent(category, action, label, value, cb) {
);
}

app.get('/', function(req, res, next) {
app.get('/', function (req, res, next) {
trackEvent(
'Example category',
'Example action',
'Example label',
'100', // Event value must be numeric.
function(err) {
function (err) {
// This sample treats an event tracking error as a fatal error. Depending
// on your application's needs, failing to track an event may not be
// considered an error.
Expand All @@ -68,9 +68,8 @@ app.get('/', function(req, res, next) {
});

// Start the server
var server = app.listen(process.env.PORT || 8080, '0.0.0.0', function() {
console.log('App listening at http://%s:%s', server.address().address,
server.address().port);
var server = app.listen(process.env.PORT || 8080, function () {
console.log('App listening on port %s', server.address().port);
console.log('Press Ctrl+C to quit.');
});
// [END app]
5 changes: 3 additions & 2 deletions appengine/bower/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
'use strict';

var express = require('express');
var path = require('path');

var app = express();

// Setup view engine
app.set('view engine', 'jade');

app.use(express.static(__dirname + '/public'));
app.use(express.static(path.join(__dirname, '/public')));

app.get('/', function(req, res) {
app.get('/', function (req, res) {
res.render('index');
});

Expand Down
21 changes: 12 additions & 9 deletions appengine/cloudsql/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var connection = mysql.createConnection({
database: process.env.MYSQL_DATABASE
});

app.get('/', function(req, res, next) {
app.get('/', function (req, res, next) {
var hash = crypto.createHash('sha256');

// Add this visit to the database
Expand All @@ -43,17 +43,21 @@ app.get('/', function(req, res, next) {
userIp: hash.update(req.ip).digest('hex').substr(0, 7)
};

connection.query('INSERT INTO `visits` SET ?', visit, function(err) {
if (err) { return next(err); }
connection.query('INSERT INTO `visits` SET ?', visit, function (err) {
if (err) {
return next(err);
}

// Query the last 10 visits from the database.
connection.query(
'SELECT `timestamp`, `userIp` FROM `visits` ORDER BY `timestamp` DESC ' +
'LIMIT 10',
function(err, results) {
if (err) { return next(err); }
function (err, results) {
if (err) {
return next(err);
}

var visits = results.map(function(visit) {
var visits = results.map(function (visit) {
return format(
'Time: %s, AddrHash: %s',
visit.timestamp,
Expand All @@ -68,9 +72,8 @@ app.get('/', function(req, res, next) {
});
});

var server = app.listen(process.env.PORT || 8080, '0.0.0.0', function() {
console.log('App listening at http://%s:%s', server.address().address,
server.address().port);
var server = app.listen(process.env.PORT || 8080, function () {
console.log('App listening on port %s', server.address().port);
console.log('Press Ctrl+C to quit.');
});
// [END app]
8 changes: 5 additions & 3 deletions appengine/cloudsql/create_tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var prompt = require('prompt');

prompt.start();

prompt.get(['host', 'user', 'password', 'database'], function(err, config) {
prompt.get(['host', 'user', 'password', 'database'], function (err, config) {
if (err) { return; }

config.multipleStatements = true;
Expand All @@ -33,8 +33,10 @@ prompt.get(['host', 'user', 'password', 'database'], function(err, config) {
' `timestamp` DATETIME NULL,' +
' `userIp` VARCHAR(46) NULL,' +
' PRIMARY KEY (`id`));',
function(err) {
if (err) { throw err; }
function (err) {
if (err) {
throw err;
}
console.log('Done!');
connection.end();
}
Expand Down
21 changes: 12 additions & 9 deletions appengine/datastore/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var dataset = gcloud.datastore({
projectId: process.env.GCLOUD_PROJECT
});

app.get('/', function(req, res, next) {
app.get('/', function (req, res, next) {
var hash = crypto.createHash('sha256');

// Add this visit to the datastore
Expand All @@ -40,18 +40,22 @@ app.get('/', function(req, res, next) {
// Store a hash of the ip address
userIp: hash.update(req.ip).digest('hex').substr(0, 7)
}
}, function(err) {
if (err) { return next(err); }
}, function (err) {
if (err) {
return next(err);
}

// Query the last 10 visits from the datastore.
var query = dataset.createQuery('visit')
.order('-timestamp')
.limit(10);

dataset.runQuery(query, function(err, entities) {
if (err) { return next(err); }
dataset.runQuery(query, function (err, entities) {
if (err) {
return next(err);
}

var visits = entities.map(function(entity) {
var visits = entities.map(function (entity) {
return format(
'Time: %s, AddrHash: %s',
entity.data.timestamp,
Expand All @@ -67,9 +71,8 @@ app.get('/', function(req, res, next) {
});

/* Start the server */
var server = app.listen(process.env.PORT || 8080, '0.0.0.0', function() {
console.log('App listening at http://%s:%s', server.address().address,
server.address().port);
var server = app.listen(process.env.PORT || 8080, function () {
console.log('App listening on port %s', server.address().port);
console.log('Press Ctrl+C to quit.');
});
// [END app]
19 changes: 11 additions & 8 deletions appengine/disk/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,22 @@ var crypto = require('crypto');
var app = express();
app.enable('trust proxy');

app.get('/', function(req, res, next) {
app.get('/', function (req, res, next) {
var instanceId = process.env.GAE_MODULE_INSTANCE || '1';
var hash = crypto.createHash('sha256');
// Only store a hash of the ip address
var ip = hash.update(req.ip).digest('hex').substr(0, 7);
var userIp = util.format('%s\n', ip);

fs.appendFile('/tmp/seen.txt', userIp, function(err) {
if (err) { return next(err); }
fs.appendFile('/tmp/seen.txt', userIp, function (err) {
if (err) {
return next(err);
}

fs.readFile('/tmp/seen.txt', function(err, data) {
if (err) { return next(err); }
fs.readFile('/tmp/seen.txt', function (err, data) {
if (err) {
return next(err);
}

res.set('Content-Type', 'text/plain');
res.status(200).send(util.format(
Expand All @@ -44,9 +48,8 @@ app.get('/', function(req, res, next) {
});
});

var server = app.listen(process.env.PORT || 8080, '0.0.0.0', function() {
console.log('App listening at http://%s:%s', server.address().address,
server.address().port);
var server = app.listen(process.env.PORT || 8080, function () {
console.log('App listening on port %s', server.address().port);
console.log('Press Ctrl+C to quit.');
});
// [END app]
9 changes: 4 additions & 5 deletions appengine/endpoints/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());

app.post('/echo', function(req, res) {
app.post('/echo', function (req, res) {
res.status(200).json({message: req.body.message});
});

function authInfoHandler(req, res) {
function authInfoHandler (req, res) {
var authUser = {id: 'anonymous'};
var encodedInfo = req.get('X-Endpoint-API-UserInfo');
if (encodedInfo) {
Expand All @@ -37,8 +37,7 @@ app.get('/auth/info/googlejwt', authInfoHandler);
app.get('/auth/info/googleidtoken', authInfoHandler);

// Start the server
var server = app.listen(process.env.PORT || '8080', '0.0.0.0', function() {
console.log('App listening at http://%s:%s', server.address().address,
server.address().port);
var server = app.listen(process.env.PORT || '8080', function () {
console.log('App listening on port %s', server.address().port);
console.log('Press Ctrl+C to quit.');
});
7 changes: 3 additions & 4 deletions appengine/errorreporting/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*jshint unused:false*/
// Copyright 2015-2016, Google, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -26,10 +25,10 @@ winston.add(winston.transports.File, {
filename: logFile
});

function report(err, req) {
function report (err, req) {
var payload = {
serviceContext: {
service: 'myapp',
service: 'myapp'
},
message: err.stack,
context: {
Expand All @@ -39,7 +38,7 @@ function report(err, req) {
referrer: req.header('Referer'),
userAgent: req.header('User-Agent'),
remoteIp: req.ip,
responseStatusCode: 500,
responseStatusCode: 500
}
}
};
Expand Down
16 changes: 10 additions & 6 deletions appengine/express-memcached-session/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ app.use(session({
})
}));

app.get('/', function(req, res){
app.get('/', function (req, res, next) {
publicIp.v4(function (err, ip) {
if (err) {
return next(err);
}
var hash = crypto.createHash('sha256');

// This shows the hashed IP for each
// This shows the hashed IP for each
res.write('<div>' + hash.update(ip).digest('hex').substr(0, 7) + '</div>');

if(req.session.views) {
if (req.session.views) {
++req.session.views;
} else {
req.session.views = 1;
Expand All @@ -49,9 +52,10 @@ app.get('/', function(req, res){
});

if (module === require.main) {
app.listen(process.env.PORT || 8080, function() {
console.log('Listening on %d', this.address().port);
});
var server = app.listen(process.env.PORT || 8080, function () {
console.log('App listening on port %d', server.address().port);
});
console.log('Press Ctrl+C to quit.');
}

module.exports = app;
7 changes: 3 additions & 4 deletions appengine/express/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ app.use('/', routes);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
app.use(function (req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
Expand All @@ -49,7 +49,7 @@ app.use(function(req, res, next) {
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res) {
app.use(function (err, req, res) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
Expand All @@ -60,13 +60,12 @@ if (app.get('env') === 'development') {

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res) {
app.use(function (err, req, res) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});


module.exports = app;
2 changes: 1 addition & 1 deletion appengine/express/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var express = require('express');
var router = express.Router();

// [START hello_world]
router.get('/', function(req, res) {
router.get('/', function (req, res) {
res.render('index', {
title: 'Hello World! Express.js on Google App Engine.'
});
Expand Down
2 changes: 1 addition & 1 deletion appengine/express/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function(req, res) {
router.get('/', function (req, res) {
res.send('respond with a resource');
});

Expand Down
Loading

0 comments on commit d8d4589

Please sign in to comment.