Skip to content
This repository has been archived by the owner on Jun 21, 2019. It is now read-only.

Commit

Permalink
Merge branch 'staging' into vagrant
Browse files Browse the repository at this point in the history
  • Loading branch information
YashoSharma authored Jun 2, 2017
2 parents 43faba5 + 9af9dbe commit a4f80e6
Show file tree
Hide file tree
Showing 143 changed files with 5,750 additions and 5,857 deletions.
95 changes: 95 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"env": {
"browser": true,
"es6": true,
"node": true,
"mocha": true
},
"plugins": ["node"],
"extends": [
"eslint:recommended",
"plugin:node/recommended"
],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2016
},
"rules": {
"strict": ["error", "global"],
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single",
{
"avoidEscape": true
}
],
"semi": [
"error",
"always"
],
"node/exports-style": [
"error",
"module.exports"
],
"node/no-unpublished-require": ["error", {
"allowModules": ["chai", "sinon", "mock-knex", "chai-as-promised", "mockery", "redis-mock"],
"tryExtensions": [".js", ".json", ".node"]
}],
"prefer-const": "error",
"no-var": "error",
"prefer-arrow-callback": "error",
"no-template-curly-in-string": "error",
"array-callback-return": "error",
"default-case": "error",
"curly": "error",
"guard-for-in": "error",
"no-else-return": "error",
"no-empty-function": "error",
"no-extra-bind": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-loop-func": "error",
"no-multi-spaces": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-return-assign": ["error", "except-parens"],
"no-return-await": "error",
"no-script-url": "error",
"no-self-compare": "error",
"no-throw-literal": "error",
"no-unmodified-loop-condition": "error",
"no-unused-expressions": "error",
"no-useless-call": "error",
"no-useless-concat": "error",
"no-useless-escape": "error",
"no-useless-return": "error",
"no-void": "error",
"yoda": ["error", "never"],
"no-catch-shadow": "error",
"array-bracket-spacing": ["error", "never", {
"singleValue": true,
"objectsInArrays": true,
"arraysInArrays": true
}],
"block-spacing": "error",
"brace-style": "error",
"comma-dangle": ["error", "never"],
"comma-spacing": "error",
"comma-style": "error",
"computed-property-spacing": "error",
"func-call-spacing": "error",
"key-spacing": "error",
"arrow-body-style": "error",
"arrow-parens": "error",
"arrow-spacing": "error"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ temp
.env

.vagrant
.eslintcache
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "4.6"
- "6.10.3"
env:
- CXX=g++-4.8
addons:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,5 @@ Environment variables should be set in `test.config`. With these values set, run
``` shell
npm test
```

which will output the test results, as well as any linter errors that may occur
25 changes: 14 additions & 11 deletions api.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
var express = require('express');
var requid = require('cuid');
var helmet = require('helmet');
const express = require('express');
const requid = require('cuid');
const helmet = require('helmet');

var config = require('./api/config');
var database = require('./api/database');
var logger = require('./api/logging');
const config = require('./api/config');
const database = require('./api/database'); // eslint-disable-line no-unused-vars
const logger = require('./api/logging');

// the dirname is local to every module, so we expose the app root's cwd
// here (before initializing the api)
config.cwd = process.__dirname;

var instance = express();
const instance = express();
instance.use(helmet());
instance.use(function (req, res, next) { req.id = requid(); next(); });
instance.use((req, res, next) => {
req.id = requid();
next();
});

var api = require('./api/');
const api = require('./api/');
instance.use('/v1', api.v1);

instance.listen(config.port, function() {
logger.info("initialized api (http://localhost:%d)", config.port);
instance.listen(config.port, () => {
logger.info('initialized api (http://localhost:%d)', config.port);
});
28 changes: 14 additions & 14 deletions api/cache.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
var config = require('./config');
var logger = require('./logging');
const config = require('./config');
const logger = require('./logging');

var _Promise = require('bluebird');
var redis = require('redis');
const _Promise = require('bluebird');
const redis = require('redis');

_Promise.promisifyAll(redis.RedisClient.prototype);
if(redis.Multi) {
_Promise.promisifyAll(redis.Multi.prototype);
_Promise.promisifyAll(redis.Multi.prototype);
}

_REDIS_CONFIG = {
host: config.redis.host,
port: config.redis.port
const _REDIS_CONFIG = {
host: config.redis.host,
port: config.redis.port
};

function CacheManager () {
logger.info("connecting to cache");
logger.info('connecting to cache');

this._cache = redis.createClient(_REDIS_CONFIG);
this._cache.on("error", function (err) {
logger.error(err);
});
this._cache = redis.createClient(_REDIS_CONFIG);
this._cache.on('error', (err) => {
logger.error(err);
});
}

CacheManager.prototype.constructor = CacheManager;

CacheManager.prototype.instance = function() {
return this._cache;
return this._cache;
};

module.exports = new CacheManager();
44 changes: 26 additions & 18 deletions api/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* jshint esversion: 6 */
/* eslint-disable no-process-exit, no-console */

// NOTE: all durations are expressed using notation understood by the
// `ms` NPM module. These durations must be converted before they are used.
Expand All @@ -7,17 +8,23 @@ const DEVELOPMENT_IDENTIFIER = 'development';
const PRODUCTION_IDENTIFIER = 'production';
const TEST_IDENTIFIER = 'test';

var config = {};
config.auth = { };
config.aws = { defaults: {} };
const config = {};
config.auth = {};
config.aws = {
defaults: {}
};
config.database = {};
config.redis = {};
config.database.primary = { pool: {} };
config.database.primary = {
pool: {}
};
config.mail = {};
config.logs = {};
config.storage = {};
config.superuser = {};
config.token = { expiration: {} };
config.token = {
expiration: {}
};

config.environment = process.env.NODE_ENV;
config.isProduction = (config.environment === PRODUCTION_IDENTIFIER);
Expand All @@ -33,9 +40,10 @@ config.auth.secret = config.secret;
config.auth.header = 'Authorization';
config.auth.expiration = '7d';

var sharedAWSCreds = new (require('aws-sdk').SharedIniFileCredentials)();
const sharedAWSCreds = new(require('aws-sdk')
.SharedIniFileCredentials)();
config.aws.enabled = (process.env.AWS && !!parseInt(process.env.AWS));
config.aws.defaults.credentials = (!!sharedAWSCreds.accessKeyId) ? sharedAWSCreds : undefined;
config.aws.defaults.credentials = (sharedAWSCreds.accessKeyId) ? sharedAWSCreds : undefined;
config.aws.defaults.region = 'us-east-1';
config.aws.defaults.sslEnabled = true;

Expand All @@ -56,31 +64,31 @@ config.redis.port = process.env.REDIS_PORT;

config.mail.key = process.env.HACKILLINOIS_MAIL_KEY;
config.mail.sinkhole = '.sink.sparkpostmail.com';
config.mail.whitelistedDomains = ['@hackillinois.org'];
config.mail.whitelistedLists = ['test'];
config.mail.whitelistedDomains = [ '@hackillinois.org' ];
config.mail.whitelistedLists = [ 'test' ];

config.logs.streamPrefix = 'instances';
config.logs.groupName = (!config.isProduction) ? 'api-dev' : 'api';

config.storage.bucketExtension = (!config.isProduction) ? '-development' : '-2017';

var exit = true;
let exit = true;
if (!(config.isProduction || config.isDevelopment || config.isTest)) {
console.error("error: set NODE_ENV to '%s', '%s', or '%s'", PRODUCTION_IDENTIFIER, DEVELOPMENT_IDENTIFIER, TEST_IDENTIFIER);
console.error("error: set NODE_ENV to '%s', '%s', or '%s'", PRODUCTION_IDENTIFIER, DEVELOPMENT_IDENTIFIER, TEST_IDENTIFIER);
} else if (!config.superuser.email) {
console.error("error: set configuration key 'HACKILLINOIS_SUPERUSER_EMAIL' to the desired admin email");
console.error("error: set configuration key 'HACKILLINOIS_SUPERUSER_EMAIL' to the desired admin email");
} else if (!config.superuser.password) {
console.error("error: set configuration key 'HACKILLINOIS_SUPERUSER_PASSWORD' to a secure, random string");
console.error("error: set configuration key 'HACKILLINOIS_SUPERUSER_PASSWORD' to a secure, random string");
} else if (!config.secret) {
console.error("error: set configuration key 'HACKILLINOIS_SECRET' to a secure, random string");
console.error("error: set configuration key 'HACKILLINOIS_SECRET' to a secure, random string");
} else if (config.isProduction && !config.mail.key) {
console.error("error: set configuration key 'HACKILLINOIS_MAIL_KEY' to the mailing provider's API key");
console.error("error: set configuration key 'HACKILLINOIS_MAIL_KEY' to the mailing provider's API key");
} else {
exit = false;
exit = false;
}
if (exit) {
console.error("fatal: environment incomplete. shutting down...");
process.exit();
console.error('fatal: environment incomplete. shutting down...');
process.exit();
}

module.exports = config;
50 changes: 25 additions & 25 deletions api/database.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
var config = require('./config');
var logger = require('./logging');

var milliseconds = require('ms');

var KNEX_CONFIG = {
client: 'mysql',
connection: {
host: config.database.primary.host,
port: config.database.primary.port,
user: config.database.primary.user,
password: config.database.primary.password,
database: config.database.primary.name
},
pool: {
min: config.database.primary.pool.min,
max: config.database.primary.pool.max,
idleTimeout: milliseconds(config.database.primary.pool.idleTimeout)
}
const config = require('./config');
const logger = require('./logging');

const milliseconds = require('ms');

const KNEX_CONFIG = {
client: 'mysql',
connection: {
host: config.database.primary.host,
port: config.database.primary.port,
user: config.database.primary.user,
password: config.database.primary.password,
database: config.database.primary.name
},
pool: {
min: config.database.primary.pool.min,
max: config.database.primary.pool.max,
idleTimeout: milliseconds(config.database.primary.pool.idleTimeout)
}
};

function DatabaseManager() {
logger.info("connecting to database");
this._knex = require('knex')(KNEX_CONFIG);
logger.info('connecting to database');
this._knex = require('knex')(KNEX_CONFIG);

this._bookshelf = require('bookshelf')(this._knex);
this._bookshelf.plugin('pagination');
this._bookshelf = require('bookshelf')(this._knex);
this._bookshelf.plugin('pagination');
}

DatabaseManager.prototype.constructor = DatabaseManager;

DatabaseManager.prototype.instance = function() {
return this._bookshelf;
return this._bookshelf;
};

DatabaseManager.prototype.connection = function () {
return this._knex;
return this._knex;
};

module.exports = new DatabaseManager();
Loading

0 comments on commit a4f80e6

Please sign in to comment.