From 25d28720dd8dfc0bbd9a8082cbd9bdd73f0353d0 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 12 Oct 2017 17:26:35 -0400 Subject: [PATCH] Add different env configs --- config/default.json | 3 +++ config/dev.json | 3 +++ config/test.json | 3 +++ gulpfile.js | 13 +++++++++++++ package.json | 18 ++++++++++++++---- public/views/index.html | 7 ++----- public/views/panel.html | 3 +-- public/views/register.html | 6 +----- server.js | 29 ++++++++++++++++------------- 9 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 config/default.json create mode 100644 config/dev.json create mode 100644 config/test.json create mode 100644 gulpfile.js diff --git a/config/default.json b/config/default.json new file mode 100644 index 0000000..180ad5c --- /dev/null +++ b/config/default.json @@ -0,0 +1,3 @@ +{ + "dbHost": "mongodb://localhost/shimapan" +} diff --git a/config/dev.json b/config/dev.json new file mode 100644 index 0000000..180ad5c --- /dev/null +++ b/config/dev.json @@ -0,0 +1,3 @@ +{ + "dbHost": "mongodb://localhost/shimapan" +} diff --git a/config/test.json b/config/test.json new file mode 100644 index 0000000..d39e6e2 --- /dev/null +++ b/config/test.json @@ -0,0 +1,3 @@ +{ + "dbHost": "mongodb://localhost/shimapan-test" +} \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..2533d85 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,13 @@ +var gulp = require('gulp'); +var concat = require('gulp-concat'); +var rename = require('gulp-rename'); +var uglify = require('gulp-uglify'); + +var jsFiles = 'public/js/**/*.js', + jsDest = 'public/libs/app'; + +gulp.task('concat', function() { + return gulp.src(jsFiles) + .pipe(concat('app.js')) + .pipe(gulp.dest(jsDest)); +}); diff --git a/package.json b/package.json index 5dc7f8a..484d138 100644 --- a/package.json +++ b/package.json @@ -6,13 +6,14 @@ "angular-ui-router": "^0.4.3", "async": "^2.5.0", "body-parser": "^1.18.2", - "express": "latest", + "config": "^1.26.2", + "express": "^4.16.2", "express-jwt": "^5.3.0", - "gulp": "latest", "jsonwebtoken": "^8.1.0", "jwt-sign": "^0.1.0", "method-override": "latest", - "mongoose": "latest", + "mongoose": "^4.12.1", + "morgan": "^1.9.0", "multer": "^1.3.0", "ng-file-upload": "^12.2.13", "passport": "^0.4.0", @@ -20,7 +21,16 @@ }, "description": "A simple file sharing website.", "main": "index.js", - "devDependencies": {}, + "devDependencies": { + "chai": "^4.1.2", + "chai-http": "^3.0.0", + "gulp": "latest", + "gulp-concat": "^2.6.1", + "gulp-rename": "^1.2.2", + "gulp-uglify": "^3.0.0", + "mocha": "^4.0.1", + "nyc": "^11.2.1" + }, "author": "Jack Foltz", "license": "WTFPL", "scripts": { diff --git a/public/views/index.html b/public/views/index.html index bb81942..81dca7f 100644 --- a/public/views/index.html +++ b/public/views/index.html @@ -14,11 +14,8 @@ - - - - - + +
diff --git a/public/views/panel.html b/public/views/panel.html index 9df9236..c9e5312 100644 --- a/public/views/panel.html +++ b/public/views/panel.html @@ -12,8 +12,7 @@ - - +
diff --git a/public/views/register.html b/public/views/register.html index 19546ad..ba14237 100644 --- a/public/views/register.html +++ b/public/views/register.html @@ -10,11 +10,7 @@ - - - - - +
diff --git a/server.js b/server.js index 58c9255..7022da0 100644 --- a/server.js +++ b/server.js @@ -2,30 +2,31 @@ var express = require('express'); var bodyParser = require('body-parser'); var methodOverride = require('method-override'); var mongoose = require('mongoose'); +var morgan = require('morgan'); var passport = require('passport'); var app = express(); -mongoose.connect('mongodb://localhost/shimapan', {useMongoClient: true}); +var config = require('config'); +if(config.util.getEnv('NODE_ENV') !== 'test') { + app.use(morgan('combined')); +} + +mongoose.Promise = global.Promise; +mongoose.connect(config.dbHost, {useMongoClient: true}); var db = mongoose.connection; db.on('error', function(err) { - if (err) - console.log('MongoDB Connection Error: ', err); - else - console.log('MongoDB Connection Established'); - -}); -db.once('open', function() { - console.log('MongoDB Connection Open') + if (err) console.log('MongoDB Connection Error: ', err); }); require('./config/passport.js'); app.use(bodyParser.json()); -app.use(bodyParser.json({ type: 'application/vnd.api+json' })); +app.use(bodyParser.json({ type: 'application/json' })); app.use(bodyParser.urlencoded({ extended: true })); -app.use(passport.initialize()); +app.use(bodyParser.text()); app.use(methodOverride('X-HTTP-Method-Override')); +app.use(passport.initialize()); // Set /public to document root app.use(express.static(__dirname + '/public')); @@ -33,8 +34,10 @@ require('./app/routes')(app); // Start app var port = process.env.PORT || 8080; -app.listen(port); +var server = app.listen(port); console.log('Listening on port ', port, '...'); // Expose app -exports = module.exports = app; \ No newline at end of file +exports.db = db; +exports.server = server; +exports.app = app;