Skip to content
Browse files

PUt configs in a js file instead of shell script. Easier.

  • Loading branch information...
1 parent 8f2d872 commit 926dfed5d5f94fbe2032ed09fcc84b904ed9eeb6 @isaacs isaacs committed Mar 14, 2011
Showing with 52 additions and 48 deletions.
  1. +1 −0 .gitignore
  2. +0 −27 default-config
  3. +26 −0 default-config.js
  4. +8 −7 lib/couch.facade.js
  5. +8 −7 lib/emailer.js
  6. +9 −7 server.js
View
1 .gitignore
@@ -1,2 +1,3 @@
config
+config.js
node_modules
View
27 default-config
@@ -1,27 +0,0 @@
-# set these to appropriate values, and rename this file to "config"
-# make sure to quote any spaces. Syntax = sh
-
-# the couchdb where you want to reset accounts.
-export COUCH=localhost:5984
-export COUCH_USERDB=_users
-export COUCH_ADMIN=adminuser:adminpass
-export COUCH_SSL=0
-
-# email login information.
-export EMAIL_USERNAME=clifton.cunningham@gmail.com
-export EMAIL_PASSWORD=mypassword
-export EMAIL_SMTPHOST=smtp.gmail.com
-export EMAIL_SMTPPORT=465
-export EMAIL_SSL=1
-
-# Important! If using gmail, then you need to have established
-# this as an email address that you can send from.
-export EMAIL_FROM='"The npm Password Reset Bot" <user-account-bot@npmjs.org>'
-
-# where the website is running
-export HOSTNAME=localhost
-export PORT=3000
-
-# change to "development" to enable the /list page.
-# Make sure to change to production before pushing live!
-export NODE_ENV=production
View
26 default-config.js
@@ -0,0 +1,26 @@
+// set these to appropriate values, and then rename this file to "config.js"
+
+// the couchdb where you want to reset accounts.
+exports.COUCH="localhost:5984"
+exports.COUCH_USERDB="_users"
+exports.COUCH_ADMIN="adminuser:adminpass"
+exports.COUCH_SSL=0
+
+// email login information.
+exports.EMAIL_USERNAME="clifton.cunningham@gmail.com"
+exports.EMAIL_PASSWORD="mypassword"
+exports.EMAIL_SMTPHOST="smtp.gmail.com"
+exports.EMAIL_SMTPPORT=465
+exports.EMAIL_SSL=1
+
+// Important! If using gmail, then you need to have established
+// this as an email address that you can send from.
+exports.EMAIL_FROM='"The npm Password Reset Bot" <user-account-bot@npmjs.org>'
+
+// where the website is running
+exports.HOSTNAME="localhost"
+exports.PORT=3000
+
+// change to "development" to enable the /list page.
+// Make sure to change to production before pushing live!
+exports.NODE_ENV="production"
View
15 lib/couch.facade.js
@@ -9,19 +9,20 @@
*/
var base64 = require('./base64')
+ , config = require('../config')
, request = require('request')
, sys = require('sys')
- , auth = base64.encode(process.env.COUCH_ADMIN)
- , couchssl = +process.env.COUCH_SSL === 1 ? true : false
+ , auth = base64.encode(config.COUCH_ADMIN)
+ , couchssl = +config.COUCH_SSL === 1 ? true : false
, headers = { 'accept':'application/json',
- 'host':process.env.COUCH,
+ 'host':config.COUCH,
'content-type':'application/json',
'authorization':'Basic ' + auth }
exports.validateUser = function(username,email,callback) {
var url = 'http' + (couchssl ? 's' : '') + '://' +
- process.env.COUCH +
- "/" + process.env.COUCH_USERDB +
+ config.COUCH +
+ "/" + config.COUCH_USERDB +
"/org.couchdb.user:" + username
console.error("validate user", url)
@@ -48,8 +49,8 @@ exports.validateUser = function(username,email,callback) {
exports.deleteUser = function(token,callback) {
var url = 'http' + (couchssl ? 's' : '') + '://' +
- process.env.COUCH +
- "/" + process.env.COUCH_USERDB +
+ config.COUCH +
+ "/" + config.COUCH_USERDB +
"/org.couchdb.user:" +
token.username +
'?rev=' + token.revision;
View
15 lib/emailer.js
@@ -2,24 +2,25 @@
* Simple emailer
*/
var email = require('nodemailer');
+var config = require('../config')
exports.Mailer = {
sendMail: function(params,callback) {
// CHANGE THESE
email.SMTP = {
- host: process.env.EMAIL_SMTPHOST,
- port: process.env.EMAIL_SMTPPORT,
- ssl: +process.env.EMAIL_SSL === 0 ? false : true,
+ host: config.EMAIL_SMTPHOST,
+ port: config.EMAIL_SMTPPORT,
+ ssl: +config.EMAIL_SSL === 0 ? false : true,
use_authentication: true,
- user: process.env.EMAIL_USERNAME,
- pass: process.env.EMAIL_PASSWORD
+ user: config.EMAIL_USERNAME,
+ pass: config.EMAIL_PASSWORD
}
console.error("sending email to "+params.email)
var un = params.username.replace(/\n\r\s\t,/g, " ")
- , from = process.env.EMAIL_FROM
+ , from = config.EMAIL_FROM
email.send_mail({
to : "\"" + un + "\" <" + params.email + ">",
@@ -37,7 +38,7 @@ exports.Mailer = {
+ "If you received this in error, you can safely ignore it.\r\n"
+ "The request will expire shortly.\r\n\r\n"
+ "You can reply to this message, or email\r\n "
- + process.env.EMAIL_FROM + "\r\nif you have questions."
+ + config.EMAIL_FROM + "\r\nif you have questions."
+ " \r\n\r\nSincerely,\r\nThe Friendly npm Password Reset Bot"
}, function(err, result){
console.error("sent to "+params.email)
View
16 server.js
@@ -8,7 +8,7 @@
/**
* Initial configuration of the Express server
*
- * Configuration from ENV
+ * Configuration from config.js
* COUCH=localhost:5984
* COUCH_USERDB=_users
* COUCH_ADMIN=adminuser:adminpass
@@ -21,6 +21,8 @@
* PORT=3000
*
**/
+var config = require("./config")
+
var envFields = [ 'COUCH',
'COUCH_USERDB',
'COUCH_ADMIN',
@@ -33,7 +35,7 @@ var envFields = [ 'COUCH',
'PORT' ];
var missing = envFields.filter(function (f) {
- return undefined === process.env[f]
+ return undefined === config[f]
})
if (missing.length) {
@@ -83,8 +85,8 @@ app.configure('development', function() {
app.use(express.logger());
app.use(express.errorHandler({ dumpExceptions: true,
showStack: true }));
- var baseUrl = process.env.HOSTNAME;
- if (process.env.PORT !== 80) baseUrl += ':' + process.env.PORT;
+ var baseUrl = config.HOSTNAME;
+ if (config.PORT !== 80) baseUrl += ':' + config.PORT;
app.set('baseUrl',baseUrl);
// Enable list in dev mode
@@ -98,8 +100,8 @@ app.configure('development', function() {
* Production configuration, no '/list' route that shows all tokens
*/
app.configure('production', function() {
- var baseUrl = process.env.HOSTNAME;
- if (process.env.PORT !== 80) baseUrl += ':' + process.env.PORT;
+ var baseUrl = config.HOSTNAME;
+ if (config.PORT !== 80) baseUrl += ':' + config.PORT;
app.set('baseUrl',baseUrl);
app.use(express.errorHandler({ dumpExceptions: false,
showStack: false }));
@@ -224,7 +226,7 @@ app.get('/confirm/:tokenId', function(req,res,next) {
/**
* Launch the server
*/
-app.listen(process.env.PORT, function (er) {
+app.listen(config.PORT, function (er) {
if (er) throw er
console.log("server started on http://"+app.set('baseUrl'))
});

0 comments on commit 926dfed

Please sign in to comment.
Something went wrong with that request. Please try again.