Skip to content
Permalink
Browse files

feat(config): Modify configuration options

- Add "port" and "host" environmental variables
- Change seeding options
- Add "force" environmental variable
- Refactor conf and seeding
  • Loading branch information...
francisdaigle committed Mar 12, 2016
1 parent d48647b commit 542d949381240a51a87c6da2b0fefb8810a10d65
Showing with 111 additions and 66 deletions.
  1. +19 −1 README.md
  2. +16 −6 config/env/development.js
  3. +2 −3 config/env/local.example.js
  4. +16 −6 config/env/production.js
  5. +16 −6 config/env/test.js
  6. +11 −13 config/lib/app.js
  7. +25 −25 config/lib/seed.js
  8. +4 −4 config/lib/sequelize.js
  9. +2 −2 package.json
@@ -100,6 +100,12 @@ In the application folder, run this from the command-line:
$ grunt
```

or in 'debugging' mode:

```
$ grunt debug
```

Your application should run on port 3000 with the *development* environment configuration, so in your browser just go to [http://localhost:3000](http://localhost:3000)

That's it! Your application should be running. To proceed with your development, check the other sections in this documentation.
@@ -125,14 +131,21 @@ In Development:
```bash
DB_SEED=true grunt
```
It will try to seed the users 'user' and 'admin'. If one of the user already exists, it will display an error message on the console. Just grab the passwords from the console.
It will try to seed the users 'user' and 'admin'. If one of the user already exists, it will display an error message on the console.

Just grab the passwords from the console.

In Production:
```bash
DB_SEED=true grunt prod
```
This will seed the admin user one time if the user does not already exist. You have to copy the password from the console and save it.

To 'force' a complete refresh of the DB, set the Sequelize 'force' option:
```bash
DB_FORCE=true DB_SEED=true grunt
```

### Running with TLS (SSL)
Application will start by default with secure configuration (SSL mode) turned on and listen on port 8443.
To run your application in a secure manner you'll need to use OpenSSL and generate a set of self-signed certificates. Unix-based users can use the following command:
@@ -169,6 +182,11 @@ And to run only the client tests, run the test:client task:
$ grunt test:client
```
And to run only the "end to end" tests, run the test:e2e task:
```bash
grunt test:e2e
```
## Running your application with Gulp
After the install process, you can easily run your project with:
@@ -68,11 +68,19 @@ module.exports = {
},
livereload: true,
roles: ['admin', 'guest', 'user'],
seedDB: {
seed: process.env.DB_SEED === 'true' ? true : false,
db: {
options: {
logResults: process.env.DB_SEED_LOG_RESULTS === 'false' ? false : true,
seedUser: {
logging: process.env.DB_LOGGING === 'true' ? console.log : false,
host: process.env.DB_HOST || 'localhost',
port: process.env.DB_PORT || '5432'
},
sync: {
force: process.env.DB_FORCE === 'true' ? true : false
}
},
seed: {
data: {
user: {
username: process.env.DB_SEED_USER_USERNAME || 'user',
provider: 'local',
email: process.env.DB_SEED_USER_EMAIL || 'user@localhost.com',
@@ -81,7 +89,7 @@ module.exports = {
displayName: 'User Local',
roles: ['user']
},
seedAdmin: {
admin: {
username: process.env.DB_SEED_ADMIN_USERNAME || 'admin',
provider: 'local',
email: process.env.DB_SEED_ADMIN_EMAIL || 'admin@localhost.com',
@@ -90,6 +98,8 @@ module.exports = {
displayName: 'Admin Local',
roles: ['user', 'admin']
}
}
},
init: process.env.DB_SEED === 'true' ? true : false,
logging: process.env.DB_SEED_LOGGING === 'false' ? false : true
}
};
@@ -20,11 +20,10 @@
module.exports = {
db: {
options: {
database: 'oc_dev',
database: 'pean_dev',
password: 'root',
username: 'root'
},
force: true
}
},
sessionSecret: process.env.SESSION_SECRET || 'youshouldchangethistosomethingsecret',
facebook: {
@@ -68,11 +68,19 @@ module.exports = {
}
},
roles: ['admin', 'guest', 'user'],
seedDB: {
seed: process.env.DB_SEED === 'true' ? true : false,
db: {
options: {
logResults: process.env.DB_SEED_LOG_RESULTS === 'false' ? false : true,
seedUser: {
logging: process.env.DB_LOGGING === 'true' ? console.log : false,
host: process.env.DB_HOST || 'localhost',
port: process.env.DB_PORT || '5432'
},
sync: {
force: process.env.DB_FORCE === 'true' ? true : false
}
},
seed: {
data: {
user: {
username: process.env.DB_SEED_USER_USERNAME || 'user',
provider: 'local',
email: process.env.DB_SEED_USER_EMAIL || 'user@localhost.com',
@@ -81,7 +89,7 @@ module.exports = {
displayName: 'User Local',
roles: ['user']
},
seedAdmin: {
admin: {
username: process.env.DB_SEED_ADMIN_USERNAME || 'admin',
provider: 'local',
email: process.env.DB_SEED_ADMIN_EMAIL || 'admin@localhost.com',
@@ -90,6 +98,8 @@ module.exports = {
displayName: 'Admin Local',
roles: ['user', 'admin']
}
}
},
init: process.env.DB_SEED === 'true' ? true : false,
logging: process.env.DB_SEED_LOGGING === 'false' ? false : true
}
};
@@ -68,11 +68,19 @@ module.exports = {
}
},
roles: ['admin', 'guest', 'user'],
seedDB: {
seed: process.env.DB_SEED === 'true' ? true : false,
db: {
options: {
logResults: process.env.DB_SEED_LOG_RESULTS === 'false' ? false : true,
seedUser: {
logging: process.env.DB_LOGGING === 'true' ? console.log : false,
host: process.env.DB_HOST || 'localhost',
port: process.env.DB_PORT || '5432'
},
sync: {
force: process.env.DB_FORCE === 'true' ? true : false
}
},
seed: {
data: {
user: {
username: process.env.DB_SEED_USER_USERNAME || 'user',
provider: 'local',
email: process.env.DB_SEED_USER_EMAIL || 'user@localhost.com',
@@ -81,7 +89,7 @@ module.exports = {
displayName: 'User Local',
roles: ['user']
},
seedAdmin: {
admin: {
username: process.env.DB_SEED_ADMIN_USERNAME || 'admin',
provider: 'local',
email: process.env.DB_SEED_ADMIN_EMAIL || 'admin@localhost.com',
@@ -90,7 +98,9 @@ module.exports = {
displayName: 'Admin Local',
roles: ['user', 'admin']
}
}
},
init: process.env.DB_SEED === 'true' ? true : false,
logging: process.env.DB_SEED_LOGGING === 'false' ? false : true
},
// This config is set to true during grunt coverage
coverage: process.env.COVERAGE || false
@@ -14,26 +14,24 @@ chalk.enabled = true;
// Initialize Models
module.exports.init = function init(callback) {

if (config.db.force) {
console.log(chalk.bold.red('Warning:\tSequelize option "force" is set to "true"'));
if (config.db.sync.force) {
console.log(chalk.bold.red('Warning:\tDB_FORCE is true'));
}

if (config.seedDB.seed) {
config.db.force = true;
}

sequelize.sequelize.sync({
force: config.db.force
}).then(function (db) {

sequelize.sequelize
.sync({
force: config.db.sync.force
})
.then(function (db) {
var app = express.init(db);

// Seed
if (config.db.force) {
if (config.db.sync.force) {
seed.setup();
}

if (config.seedDB.seed) {
console.log(chalk.bold.red('Warning:\tDatabase seeding is turned on'));
if (config.seed.init) {
console.log(chalk.bold.red('Warning:\tDB_SEED is true'));
seed.start();
}

@@ -7,7 +7,7 @@ var _ = require('lodash'),
db = require('./sequelize');

// global seed options object
var seedOptions = {};
var data = {};

/**
* Remove user
@@ -63,11 +63,11 @@ function checkUserNotExists(user) {
if (users.length === 0) {
resolve();
} else {
reject(new Error('Failed due to local account already exists: ' + user.username));
reject(new Error('Failed: local account already exists: ' + user.username));
}
})
.catch(function(err) {
reject(new Error('Failed to find local account ' + user.username));
reject(new Error('Failed: local account ' + user.username + ' does note exist'));
});
});
}
@@ -78,8 +78,8 @@ function checkUserNotExists(user) {
function reportSuccess(password) {
return function(user) {
return new Promise(function(resolve, reject) {
if (seedOptions.logResults) {
console.log(chalk.bold.red('Database Seeding:\tLocal account "' + user.username + '" added with password set to ' + password));
if (config.seed.logging) {
console.log(chalk.bold.blue('Database Seeding:\tLocal account "' + user.username + '" added with password set to ' + password));
}
resolve();
});
@@ -124,7 +124,7 @@ function seedUser(user, roles) {
// Set the new password
user.password = password;

if (user.username === seedOptions.seedAdmin.username && process.env.NODE_ENV === 'production') {
if (user.username === config.seed.data.admin.username && process.env.NODE_ENV === 'production') {
checkUserNotExists(user)
.then(saveUser(user, roles))
.then(reportSuccess(password))
@@ -155,8 +155,8 @@ function seedUser(user, roles) {
function reportError(reject) {

return function(err) {
if (seedOptions.logResults) {
console.log('Database Seeding:\t\t\t' + err);
if (config.seed.logging) {
console.log('Database Seeding:\t' + err);
}
reject(err);
};
@@ -187,35 +187,35 @@ module.exports.start = function start() {
userRoles = [];

// Initialize the default seed options
seedOptions = _.clone(config.seedDB.options, true);
data = _.clone(config.seed.data, true);

// Check for provided options
if (_.has(seedOptions, 'seedUser')) {
if (_.has(data, 'user')) {
var userAccount = db.User.build({
username: seedOptions.seedUser.username,
provider: seedOptions.seedUser.provider,
email: seedOptions.seedUser.email,
firstName: seedOptions.seedUser.firstName,
lastName: seedOptions.seedUser.lastName,
displayName: seedOptions.seedUser.displayName
username: data.user.username,
provider: data.user.provider,
email: data.user.email,
firstName: data.user.firstName,
lastName: data.user.lastName,
displayName: data.user.displayName
});

_.forEach(seedOptions.seedUser.roles, function(value) {
_.forEach(data.user.roles, function(value) {
userRoles.push(config.roles.indexOf(value) + 1);
});
}

if (_.has(seedOptions, 'seedAdmin')) {
if (_.has(data, 'admin')) {
var adminAccount = db.User.build({
username: seedOptions.seedAdmin.username,
provider: seedOptions.seedAdmin.provider,
email: seedOptions.seedAdmin.email,
firstName: seedOptions.seedAdmin.firstName,
lastName: seedOptions.seedAdmin.lastName,
displayName: seedOptions.seedAdmin.displayName
username: data.admin.username,
provider: data.admin.provider,
email: data.admin.email,
firstName: data.admin.firstName,
lastName: data.admin.lastName,
displayName: data.admin.displayName
});

_.forEach(seedOptions.seedAdmin.roles, function(value) {
_.forEach(data.admin.roles, function(value) {
adminRoles.push(config.roles.indexOf(value) + 1);
});
}
@@ -9,11 +9,11 @@ var config = require('../config'),
var db = {};

// Sequelize
var sequelize = new Sequelize(config.db.options.database, config.db.options.username, config.db.options.password, {
var sequelize = new Sequelize(config.db.database, config.db.username, config.db.password, {
dialect: 'postgres',
logging: false, // console.log
host: 'localhost',
port: '5432'
logging: config.db.options.logging,
host: config.db.options.host,
port: config.db.options.port
});

// Import models
@@ -1,8 +1,8 @@
{
"name": "peanjs",
"description": "Full-Stack JavaScript with PostgreSQL, Express, AngularJS, and Node.js.",
"version": "0.4.2",
"peanjs-version": "0.4.2",
"version": "1.0.0",
"peanjs-version": "0.0.0",
"private": false,
"author": "https://github.com/meanjs/pean/graphs/contributors",
"license": "MIT",

0 comments on commit 542d949

Please sign in to comment.
You can’t perform that action at this time.