Created
July 31, 2015 15:20
-
-
Save kevinSuttle/0d8a20bd6bda342518a6 to your computer and use it in GitHub Desktop.
Loading multiple API credentials into a Node app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var express = require('express'); | |
var app = express(); | |
var config = require('./config'); | |
// [...] | |
// [...] | |
var analytics = new Analytics(config.segment.writeKey, { flushAt: 1 }); | |
// [...] | |
app.use(cookieParser(config.session.secret)); | |
// [...] | |
app.use(expressSession({ | |
key: config.session.key, | |
// [...] | |
})); | |
// [...] | |
app.use(config.bluemix.authVerificationURL, bluemixAPI.router); | |
// [...] | |
module.exports = app; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<header class="global-header"> | |
<a class="global-header__home-link" href="{?user}/dashboard{:else}/{/user}" class="home-link">Home</> | |
<nav class="global-nav"> | |
<ul class="global-nav__list"> | |
{?user} | |
<li class="global-nav__list-item"><a href="/profile" class="global-nav__link">Profile</a> | |
<li class="global-nav__list-item"><a href="/dashboard" class="global-nav__link">Dashboard</a> | |
{/user} | |
<li class="global-nav__list-item"><a href="/catalog" class="global-nav__link">Catalog</a> | |
<li class="global-nav__list-item"> | |
<a href="{?user}/logout{:else}{config.bluemix.authVerificationURL}{/user}" class="global-nav__link">{?user}Log out {:else}Log in{/user}</a> | |
</li> | |
</ul> | |
</nav> | |
</header> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// file is in config/index.js | |
var config = { | |
session: { | |
secret: process.env.SESSION_SECRET, | |
key: process.env.SESSION_KEY | |
}, | |
github: { | |
apiURL: 'https://api.github.com/', | |
clientID: process.env.GITHUB_CLIENT_ID, | |
clientSecret: process.env.GITHUB_CLIENT_SECRET, | |
authVerificationURL: '/auth/github', | |
authCallbackURL: '/auth/github/callback', | |
authScope: process.env.GITHUB_AUTH_SCOPE | |
}, | |
cloudant: { | |
credentials: { | |
host: process.env.CLOUDANT_HOST, | |
URL: process.env.CLOUDANT_URL, | |
username: process.env.CLOUDANT_USERNAME, | |
account: process.env.CLOUDANT_ACCOUNT, | |
pw: process.env.CLOUDANT_PW, | |
port: process.env.CLOUDANT_PORT, | |
catalogDB: process.env.CLOUDANT_BLUEMIX_CATALOG_DB, | |
usersDB: process.env.CLOUDANT_BLUEMIX_USERS_DB | |
} | |
}, | |
segment: { | |
writeKey: 'xxx' | |
}, | |
crypto: { | |
workFactor: 5000, | |
keylen: 32, | |
randomSize: 256 | |
} | |
}; | |
module.exports = config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "node-multi-api", | |
"description": "Multiple API keys and environment vars for Node apps", | |
"main": "app.js", | |
"private": true, | |
"scripts": { | |
"start": "node bin/www", | |
"predev": "gulp compile-sass", | |
"dev": ". ./config/set-dev-env.sh; nodemon ./bin/www", | |
"lint": "gulp lint-js; gulp lint-scss" | |
} | |
[...] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export NODE_ENV='development'; | |
export SESSION_SECRET=; | |
export SESSION_KEY=''; | |
# GitHub OAuth Dev | |
export GITHUB_CLIENT_ID= ; | |
export GITHUB_CLIENT_SECRET= ; | |
export GITHUB_AUTH_SCOPE='[ user, repo, repo:status, repo_deployment, read:org ]'; | |
# Cloudant Bluemix Service | |
export CLOUDANT_BLUEMIX_CATALOG_DB=bluemix-beta-catalog-dev; | |
export CLOUDANT_BLUEMIX_USERS_DB=bluemix-beta-users-dev; | |
export CLOUDANT_HOST=https://xxx-bluemix.cloudant.com/; | |
export CLOUDANT_USERNAME=xxx-bluemix; | |
export CLOUDANT_URL=https:zzz-bluemix.cloudant.com; | |
export CLOUDANT_PW= ; | |
export CLOUDANT_PORT=443; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment