1
0
Fork 0
mirror of https://github.com/mmumshad/ansible-playable.git synced 2025-03-09 23:38:54 +00:00

Initial Commit

This commit is contained in:
Mumshad Mannambeth 2017-06-07 13:36:44 -04:00
commit c92f737237
273 changed files with 16964 additions and 0 deletions

View file

@ -0,0 +1,16 @@
'use strict';
/*eslint no-process-env:0*/
// Development specific configuration
// ==================================
module.exports = {
// MongoDB connection options
mongo: {
uri: 'mongodb://db/app2-dev'
},
// Seed database on startup
seedDB: true
};

View file

@ -0,0 +1,66 @@
'use strict';
/*eslint no-process-env:0*/
import path from 'path';
import _ from 'lodash';
/*function requiredProcessEnv(name) {
if(!process.env[name]) {
throw new Error('You must set the ' + name + ' environment variable');
}
return process.env[name];
}*/
// All configurations will extend these options
// ============================================
var all = {
env: process.env.NODE_ENV,
// Root path of server
root: path.normalize(`${__dirname}/../../..`),
// Browser-sync port
browserSyncPort: process.env.BROWSER_SYNC_PORT || 3000,
// Server port
port: process.env.PORT || 9000,
// Server IP
ip: process.env.IP || '0.0.0.0',
// Should we populate the DB with sample data?
seedDB: false,
// Secret for session, you will want to change this and make it an environment variable
secrets: {
session: 'app2-secret'
},
// MongoDB connection options
mongo: {
options: {
db: {
safe: true
}
}
},
facebook: {
clientID: process.env.FACEBOOK_ID || 'id',
clientSecret: process.env.FACEBOOK_SECRET || 'secret',
callbackURL: `${process.env.DOMAIN || ''}/auth/facebook/callback`
},
google: {
clientID: process.env.GOOGLE_ID || 'id',
clientSecret: process.env.GOOGLE_SECRET || 'secret',
callbackURL: `${process.env.DOMAIN || ''}/auth/google/callback`
}
};
// Export the config object based on the NODE_ENV
// ==============================================
module.exports = _.merge(
all,
require('./shared'),
require(`./${process.env.NODE_ENV}.js`) || {});

View file

@ -0,0 +1,24 @@
'use strict';
/*eslint no-process-env:0*/
// Production specific configuration
// =================================
module.exports = {
// Server IP
ip: process.env.OPENSHIFT_NODEJS_IP
|| process.env.ip
|| undefined,
// Server port
port: process.env.OPENSHIFT_NODEJS_PORT
|| process.env.PORT
|| 8080,
// MongoDB connection options
mongo: {
uri: process.env.MONGODB_URI
|| process.env.MONGOHQ_URL
|| process.env.OPENSHIFT_MONGODB_DB_URL + process.env.OPENSHIFT_APP_NAME
|| 'mongodb://localhost/app2'
}
};

View file

@ -0,0 +1,11 @@
'use strict';
exports = module.exports = {
// List of user roles
userRoles: ['guest', 'user', 'admin'],
'scriptEngine' : {
'host' : 'localhost',
'user' : 'root',
'password' : 'P@ssw0rd@123'
}
};

View file

@ -0,0 +1,21 @@
'use strict';
/*eslint no-process-env:0*/
// Test specific configuration
// ===========================
module.exports = {
// MongoDB connection options
mongo: {
uri: 'mongodb://localhost/app2-test'
},
sequelize: {
uri: 'sqlite://',
options: {
logging: false,
storage: 'test.sqlite',
define: {
timestamps: false
}
}
}
};

133
server/config/express.js Normal file
View file

@ -0,0 +1,133 @@
/**
* Express configuration
*/
'use strict';
import express from 'express';
import favicon from 'serve-favicon';
import morgan from 'morgan';
import shrinkRay from 'shrink-ray';
import bodyParser from 'body-parser';
import methodOverride from 'method-override';
import cookieParser from 'cookie-parser';
import errorHandler from 'errorhandler';
import path from 'path';
import lusca from 'lusca';
import config from './environment';
import passport from 'passport';
import session from 'express-session';
import connectMongo from 'connect-mongo';
import mongoose from 'mongoose';
var MongoStore = connectMongo(session);
export default function(app) {
var env = app.get('env');
if(env === 'development' || env === 'test') {
app.use(express.static(path.join(config.root, '.tmp')));
}
if(env === 'production') {
app.use(favicon(path.join(config.root, 'client', 'favicon.ico')));
}
app.set('appPath', path.join(config.root, 'client'));
app.use(express.static(app.get('appPath')));
app.use(morgan('dev'));
app.set('views', `${config.root}/server/views`);
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(shrinkRay());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(cookieParser());
app.use(passport.initialize());
// Persist sessions with MongoStore / sequelizeStore
// We need to enable sessions for passport-twitter because it's an
// oauth 1.0 strategy, and Lusca depends on sessions
app.use(session({
secret: config.secrets.session,
saveUninitialized: true,
resave: false,
store: new MongoStore({
mongooseConnection: mongoose.connection,
db: 'app2'
})
}));
/**
* Lusca - express server security
* https://github.com/krakenjs/lusca
*/
if(env !== 'test' && !process.env.SAUCE_USERNAME) {
app.use(lusca({
csrf: {
angular: true
},
xframe: 'SAMEORIGIN',
hsts: {
maxAge: 31536000, //1 year, in seconds
includeSubDomains: true,
preload: true
},
xssProtection: true
}));
}
if(env === 'development') {
const webpackDevMiddleware = require('webpack-dev-middleware');
const stripAnsi = require('strip-ansi');
const webpack = require('webpack');
const makeWebpackConfig = require('../../webpack.make');
const webpackConfig = makeWebpackConfig({ DEV: true });
const compiler = webpack(webpackConfig);
const browserSync = require('browser-sync').create();
/**
* Run Browsersync and use middleware for Hot Module Replacement
*/
browserSync.init({
open: false,
logFileChanges: false,
proxy: `localhost:${config.port}`,
ws: true,
middleware: [
webpackDevMiddleware(compiler, {
noInfo: false,
stats: {
colors: true,
timings: true,
chunks: false
}
})
],
port: config.browserSyncPort,
plugins: ['bs-fullscreen-message']
});
/**
* Reload all devices when bundle is complete
* or send a fullscreen error message to the browser instead
*/
compiler.plugin('done', function(stats) {
console.log('webpack done hook');
if(stats.hasErrors() || stats.hasWarnings()) {
return browserSync.sockets.emit('fullscreen:message', {
title: 'Webpack Error:',
body: stripAnsi(stats.toString()),
timeout: 100000
});
}
browserSync.reload();
});
}
if(env === 'development' || env === 'test') {
app.use(errorHandler()); // Error handler - has to be last
}
}

View file

@ -0,0 +1,20 @@
'use strict';
// Use local.env.js for environment variables that will be set when the server starts locally.
// Use for your api keys, secrets, etc. This file should not be tracked by git.
//
// You will need to set these on the server you deploy to.
module.exports = {
DOMAIN: 'http://localhost:9000',
SESSION_SECRET: 'app2-secret',
FACEBOOK_ID: 'app-id',
FACEBOOK_SECRET: 'secret',
GOOGLE_ID: 'app-id',
GOOGLE_SECRET: 'secret',
// Control debug level for modules using visionmedia/debug
DEBUG: ''
};

66
server/config/seed.js Normal file
View file

@ -0,0 +1,66 @@
/**
* Populate DB with sample data on server start
* to disable, edit config/environment/index.js, and set `seedDB: false`
*/
'use strict';
import Thing from '../api/thing/thing.model';
import User from '../api/user/user.model';
import config from './environment/';
export default function seedDatabaseIfNeeded() {
if(config.seedDB) {
Thing.find({}).remove()
.then(() => {
let thing = Thing.create({
name: 'Development Tools',
info: 'Integration with popular tools such as Webpack, Gulp, Babel, TypeScript, Karma, '
+ 'Mocha, ESLint, Node Inspector, Livereload, Protractor, Pug, '
+ 'Stylus, Sass, and Less.'
}, {
name: 'Server and Client integration',
info: 'Built with a powerful and fun stack: MongoDB, Express, '
+ 'AngularJS, and Node.'
}, {
name: 'Smart Build System',
info: 'Build system ignores `spec` files, allowing you to keep '
+ 'tests alongside code. Automatic injection of scripts and '
+ 'styles into your index.html'
}, {
name: 'Modular Structure',
info: 'Best practice client and server structures allow for more '
+ 'code reusability and maximum scalability'
}, {
name: 'Optimized Build',
info: 'Build process packs up your templates as a single JavaScript '
+ 'payload, minifies your scripts/css/images, and rewrites asset '
+ 'names for caching.'
}, {
name: 'Deployment Ready',
info: 'Easily deploy your app to Heroku or Openshift with the heroku '
+ 'and openshift subgenerators'
});
return thing;
})
.then(() => console.log('finished populating things'))
.catch(err => console.log('error populating things', err));
User.find({}).remove()
.then(() => {
User.create({
provider: 'local',
name: 'Test User',
email: 'test@example.com',
password: 'test'
}, {
provider: 'local',
role: 'admin',
name: 'Admin',
email: 'admin@example.com',
password: 'admin'
})
.then(() => console.log('finished populating users'))
.catch(err => console.log('error populating users', err));
});
}
}