added socketPort option

This commit is contained in:
David Baldwynn 2017-04-03 13:28:24 -07:00
parent 9c9dd633e8
commit 1058692bca
No known key found for this signature in database
GPG key ID: 15D1C13202224A9B
8 changed files with 63 additions and 45 deletions

View file

@ -60,6 +60,7 @@ COPY ./config /opt/tellform/config
COPY ./gruntfile.js /opt/tellform/gruntfile.js
COPY ./server.js /opt/tellform/server.js
COPY ./.env /opt/tellform/.env
COPY ./scripts/create_admin.js /opt/tellform/scripts/create_admin.js
# Run TellForm server
CMD npm start

View file

@ -61,6 +61,7 @@ COPY ./config /opt/tellform/config
COPY ./gruntfile.js /opt/tellform/gruntfile.js
COPY ./server.js /opt/tellform/server.js
COPY ./.env /opt/tellform/.env
COPY ./scripts/create_admin.js /opt/tellform/scripts/create_admin.js
RUN grunt build

View file

@ -111,8 +111,14 @@ Then run these commands
```
$ docker run -p 27017:27017 -d --name some-mongo mongo
$ docker run -p 6379:6379 -d --name some-redis redis
$ docker run --rm -p 3000:3000 --link some-redis:redis-db --link some-mongo:db tellform/development
$ docker run -p 127.0.0.1:6379:6379 -d --name some-redis redis
$ docker run --rm -p 3000:3000 --link some-redis:redis-db --link some-mongo:db tellform/development -e MAILER_EMAIL_ID='mailer_username' \
-e POSTGRES_ENV_POSTGRES_PASSWORD='foo' \
-e POSTGRES_ENV_POSTGRES_USER='bar' \
-e POSTGRES_ENV_DB_NAME='mysite_staging' \
-e POSTGRES_PORT_5432_TCP_ADDR='docker-db-1.hidden.us-east-1.rds.amazonaws.com' \
-e SITE_URL='staging.mysite.com' \
-p 80:80 \
```
## Testing Your Application

View file

@ -3,7 +3,7 @@
module.exports = {
baseUrl: process.env.BASE_URL || 'http://localhost:5000',
db: {
uri: 'mongodb://'+( process.env.DB_PORT_27017_TCP_ADDR || process.env.DB_HOST || 'localhost') +'/mean',
uri: 'mongodb://'+( process.env.DB_PORT_27017_TCP_ADDR || process.env.DB_HOST || '0.0.0.0') +'/mean',
options: {
user: '',
pass: ''

View file

@ -3,7 +3,7 @@
module.exports = {
baseUrl: process.env.BASE_URL || process.env.HEROKU_APP_NAME + '.herokuapp.com' || 'tellform.com',
db: {
uri: process.env.MONGODB_URI || process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean',
uri: process.env.MONGODB_URI || process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || '0.0.0.0') + '/mean',
},
port: process.env.PORT || 5000,
socketUrl: process.env.SOCKET_URL || 'ws.tellform.com',

View file

@ -9,9 +9,12 @@ var config = require('./config'),
// Define the Socket.io configuration method
module.exports = function (app, db) {
var server = http.createServer(app);
var io = socketio({ transports: ['websocket', 'polling'] });
if(config.socketPort){
io = socketio(config.socketPort, { transports: ['websocket', 'polling'] });
}
if(process.env.DISABLE_CLUSTER_MODE !== "TRUE"){
var redis = require('socket.io-redis');
io.adapter(redis( process.env.REDIS_URL || { host: process.env.REDIS_DB_PORT_6379_TCP_ADDR || '127.0.0.1' , port: process.env.REDIS_DB_PORT_6379_TCP_PORT || 6379 }));

View file

@ -1,50 +1,45 @@
var init = require('../config/init')(),
config = require('../config/config'),
var config = require('../config/config'),
mongoose = require('mongoose'),
chalk = require('chalk'),
fs = require('fs-extra');
// Bootstrap db connection
var db = mongoose.connect(config.db.uri, config.db.options, function(err) {
if (err) {
console.error(chalk.red('Could not connect to MongoDB!'));
console.log(chalk.red(err));
}
});
mongoose.connection.on('error', function(err) {
console.error(chalk.red('MongoDB connection error: ' + err));
process.exit(-1);
});
exports.run = function(app, db, cb) {
// Init the express application
var app = require('../config/express')(db);
var User = mongoose.model('User');
// Bootstrap passport config
require('../config/passport')();
var email = config.ADMIN_EMAIL || 'admin@admin.com';
var username = config.ADMIN_USERNAME || 'admin';
var password = config.ADMIN_PASSWORD || 'admin';
var User = mongoose.model('User');
require('../app/models/user.server.model.js');
var newUser = new User({
firstName: 'Admin',
lastName: 'Account',
email: email,
username: username,
password: password,
provider: 'local',
roles: ['admin', 'user']
});
var email = process.env.ADMIN_EMAIL;
var username = process.env.ADMIN_USERNAME;
var password = process.env.ADMIN_PASSWORD;
User.findOne({email: email}, function (err, user) {
if (err) {
cb(err);
}
user = new User({
firstName: 'Admin',
lastName: 'Account',
email: email,
username: username,
password: password,
provider: 'local',
roles: ['admin', 'user']
});
if(!user){
newUser.save(function (err) {
if (err) {
cb(err);
}
console.log(chalk.green('Successfully created Admin Account'));
delete email;
delete password;
delete username;
user.save(function (err) {
if (err) return console.error(chalk.red(err));
console.log(chalk.green('Successfully created user'));
delete email;
delete password;
delete username;
process.exit(1);
});
cb(err);
});
} else {
cb('User already exists!');
}
})
}

View file

@ -35,6 +35,18 @@ mongoose.connection.on('error', function (err) {
// Init the express application
var app = require('./config/express')(db);
//Create admin account
if (process.env.CREATE_ADMIN_ACCOUNT === 'TRUE') {
var create_admin = require('./scripts/create_admin');
create_admin.run(app, db, function(err){
if(err){
console.error(chalk.red('Could not create Admin Account: ' + err));
}
});
}
// Bootstrap passport config
require('./config/passport')();