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

Commit

Permalink
update(environment): use dotenv private files for setting ENV. Remove…
Browse files Browse the repository at this point in the history
… keys, ports, server names from code

add support for NVM
update README
remove OpenShift references

Fixes #42
  • Loading branch information
Splaktar committed Mar 12, 2017
1 parent fc22bc5 commit 3db21a4
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ dist
newrelic_agent.log
.c9
mongodb
.env
.env-prod
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.6.1
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,33 @@ The public instance of the GDG[x] Hub is hosted at [https://hub.gdgx.io]
## Install dependencies
Run `npm install`

## Configure API keys
## Configure Environment

1. Define the **simpleApiKey**: The API key for your project, available from the [Cloud Console](https://cloud.google.com/console)
1. Define the **GOOGLE_SIMPLE_API_KEY**: The API key for your project, available from the [Cloud Console](https://cloud.google.com/console)
1. Create a new project then go to APIs & Auth->APIs, activate Google+ API.
1. Go to APIs & Auth->Credentials. Add Credentials->API key->Browser key->Create (keep `Any referrer allowed` set).
1. Define the **oauthClientId** and **oauthClientSecret**: The Client Id and secret for your project, available from the [Cloud Console](https://cloud.google.com/console)
1. Define the **GOOGLE_OAUTH_CLIENT_ID** and **GOOGLE_OAUTH_CLIENT_SECRET**: The Client Id and secret for your project, available from the [Cloud Console](https://cloud.google.com/console)
1. Go to APIs & Auth->Credentials. Add Credentials->API key->OAuth 2.0 client ID->Web Application->Create.

* lib/config/keys.js
* simpleApiKey - Browser key from step 1
* oauthClientId - Web Application clientId from step 2
* oauthClientSecret - Web Application client secret from step 2
1. Create a private `.env` file in the root of the project with the following contents:
```
GOOGLE_SIMPLE_API_KEY=
GOOGLE_OAUTH_CLIENT_ID=
GOOGLE_OAUTH_CLIENT_SECRET=
SERVER_KEY_SECRET=
ANDROID_CLIENT_IDS=
MONGODB_DB_URL=
NODEJS_PORT=
NODEJS_IP=
SESSION_SECRET=
```
1. Populate the `.env` file with the following variables that were provided to you:
* GOOGLE_SIMPLE_API_KEY - Browser key from step 1
* GOOGLE_OAUTH_CLIENT_ID - Web Application clientId from step 2
* GOOGLE_OAUTH_CLIENT_SECRET - Web Application client secret from step 2
* SERVER_KEY_SECRET - Only needed for testing Frisbee integration
* ANDROID_CLIENT_IDS - Only needed for testing Frisbee integration. Needs to be a comma separated list
* SESSION_SECRET - random 34 characters
## Check Mongo Server
Run `mongostart` or `mongod`
Expand Down Expand Up @@ -57,7 +72,7 @@ Maintainer:
License
--------
© 2013-2016 GDG[x]
© 2013-2017 GDG[x]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions lib/config/env/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ var rootPath = path.normalize(__dirname + '/../../..');

module.exports = {
root: rootPath,
port: process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT || 3000,
hostname: process.env.OPENSHIFT_NODEJS_IP || undefined,
port: process.env.PORT || process.env.NODEJS_PORT || 3000,
hostname: process.env.NODEJS_IP || undefined,
mongo: {
options: {
db: {
safe: true
}
}
},
sessionSecret: 'e457jhe57hg45zth4htxdxKU&$FVrekrrj'
sessionSecret: process.env.SESSION_SECRET
};
2 changes: 1 addition & 1 deletion lib/config/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module.exports = {
env: 'development',
mongo: {
uri: 'mongodb://localhost/gdgx-hub-dev'
uri: process.env.MONGODB_DB_URL
},
mail: {
sender: 'GDG[x] Hub - Dev <[email protected]>',
Expand Down
11 changes: 5 additions & 6 deletions lib/config/env/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
module.exports = {
env: 'production',
mongo: {
uri: process.env.OPENSHIFT_MONGODB_DB_URL + process.env.OPENSHIFT_APP_NAME ||
'mongodb://mongodb-mongo-db-1gu7/hub-prod'
uri: process.env.MONGODB_DB_URL
},
mail: {
sender: 'GDG[x] Hub <[email protected]>',
transport: 'Direct',
error_recipient: '[email protected]' // jshint ignore:line
error_recipient: process.env.ADMIN_EMAIL // jshint ignore:line
},
redis: {
host: process.env.OPENSHIFT_REDIS_DB_HOST || 'redis-redis-1-vm',
port: process.env.OPENSHIFT_REDIS_DB_PORT || '6379',
password: process.env.OPENSHIFT_REDIS_DB_PASSWORD || ''
host: process.env.REDIS_DB_HOST,
port: process.env.REDIS_DB_PORT,
password: process.env.REDIS_DB_PASSWORD
}
};
2 changes: 1 addition & 1 deletion lib/config/env/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
module.exports = {
env: 'test',
mongo: {
uri: 'mongodb://localhost/gdgx-hub-test'
uri: process.env.MONGODB_DB_URL
}
};
12 changes: 6 additions & 6 deletions lib/config/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ module.exports = {
keys: {
google: {
analytics: {
trackingId: 'UA-42015512-3'
trackingId: process.env.GA_TRACKING_ID
},
simpleApiKey: process.env.GOOGLE_SIMPLE_API_KEY || '',
oauthClientId: process.env.GOOGLE_OAUTH_CLIENT_ID || '',
oauthClientSecret: process.env.GOOGLE_OAUTH_CLIENT_SECRET || ''
simpleApiKey: process.env.GOOGLE_SIMPLE_API_KEY,
oauthClientId: process.env.GOOGLE_OAUTH_CLIENT_ID,
oauthClientSecret: process.env.GOOGLE_OAUTH_CLIENT_SECRET
},
frisbee: {
serverClientId: process.env.SERVER_KEY_SECRET || '',
androidClientIds: process.env.ANDROID_CLIENT_IDS || []
serverClientId: process.env.SERVER_KEY_SECRET,
androidClientIds: process.env.ANDROID_CLIENT_IDS.split(',')
}
}
};
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ module.exports = {
console.log(err);
}
return ph.createPage(function(err, page) {
return page.open('http://' + process.env.OPENSHIFT_APP_DNS + escaped_fragment, function() {
return page.open('http://' + process.env.APP_DNS + escaped_fragment, function() {
return page.evaluate(function() {
return document.getElementsByTagName('html')[0].innerHTML;
}, function(err, result) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"connect-redis": "3.0.1",
"cron": "1.0.9",
"csurf": "1.8.3",
"dotenv": "4.0.0",
"ejs": "0.8.4",
"express": "3.21.2",
"express-annotations": "0.1.0",
Expand Down
10 changes: 10 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
'use strict';

var env = require('dotenv').config({path: process.env.NODE_ENV === 'production' ? '.env-prod' : '.env'});
if (env && !env.error) {
if (process.env.NODE_ENV !== 'production') {
console.log(JSON.stringify(env));
}
} else {
console.error(JSON.stringify(env));
}

var express = require('express'),
path = require('path'),
fs = require('fs'),
cluster = require('cluster'),
numCPUs = require('os').cpus().length,
mongoose = require('mongoose');

/**
* Main application file
*/
Expand Down

0 comments on commit 3db21a4

Please sign in to comment.