diff --git a/31-2140/app.js b/31-2140/app.js new file mode 100644 index 0000000..036095b --- /dev/null +++ b/31-2140/app.js @@ -0,0 +1,69 @@ +var express = require('express'); +var path = require('path'); +var routes = require('./routes/index'); +var api = require('./routes/api'); +var app = express(); +var quotes = require('./quotes.js'); +var mdb = require('./db.js'); + +// view engine setup +// app.set('views', path.join(__dirname, 'public')); +// app.set('view engine', 'jade'); + +var cons = require('consolidate'); +// view engine setup +app.engine('html', cons.swig) +app.set('views', path.join(__dirname, 'public')); +app.set('view engine', 'html'); + +app.use(express.static(path.join(__dirname, 'public'))); + +app.use('/api',function(req,res,next){ + req.db = quotes; + next(); +}); + +app.use('/', routes); +app.use('/index', routes); +app.use('/api', api); + +// catch 404 and forward to error handler +app.use(function(req, res, next) { + var err = new Error('Not Found'); + err.status = 404; + res.status(err.status); + res.render('error', { + status : err.status, + message: err.message, + error: err.stack + }); +}); + +// error handlers + +// development error handler +// will print stacktrace +// if (app.get('env') === 'development') { +// app.use(function(err, req, res, next) { +// res.status(err.status || 500); +// res.render('error', { +// status : err.status, +// message: err.message, +// error: err.stack +// }); +// }); +// // } + +// production error handler +// no stacktraces leaked to user +// app.use(function(err, req, res, next) { +// res.status(err.status || 500); +// res.render('error', { +// status : err.status, +// message: err.message, +// error: err.stack +// }); +// }); + + +module.exports = app; diff --git a/31-2140/app.js~ b/31-2140/app.js~ new file mode 100644 index 0000000..fbd3ab3 --- /dev/null +++ b/31-2140/app.js~ @@ -0,0 +1,58 @@ +var express = require('express'); +var path = require('path'); +var logger = require('morgan'); +var cookieParser = require('cookie-parser'); +var bodyParser = require('body-parser'); + +var routes = require('./routes/index'); +var users = require('./routes/users'); + +var app = express(); + +// view engine setup +app.set('views', path.join(__dirname, 'public')); +app.set('view engine', 'jade'); + +// uncomment after placing your favicon in /public +app.use(logger('dev')); +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: false })); +app.use(cookieParser()); +app.use(express.static(path.join(__dirname, 'public'))); + +app.use('/', routes); +app.use('/api', users); + +// catch 404 and forward to error handler +app.use(function(req, res, next) { + var err = new Error('Not Found'); + err.status = 404; + next(err); +}); + +// error handlers + +// development error handler +// will print stacktrace +if (app.get('env') === 'development') { + app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: err + }); + }); +} + +// production error handler +// no stacktraces leaked to user +app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: {} + }); +}); + + +module.exports = app; diff --git a/31-2140/db.js b/31-2140/db.js new file mode 100644 index 0000000..18c61d2 --- /dev/null +++ b/31-2140/db.js @@ -0,0 +1,44 @@ +var mongo = require('mongodb').MongoClient; +var DB = null; +var dbURL = 'mongodb://localhost:27017/quotedb'; +/** + * function that connects to the mongodb instance initialized. + * @param {Function} cb callback for when connection is complete + */ +var connect = exports.connect = function(cb) { + // You do this one + mongo.connect(dbURL, function(err, db) { + // if(!err) + // console.log("We are connected"); + DB = db; + // db.createCollection('quote', function(err, collection) {}); + cb(err,DB); +}) + }; + +/** + * used to get access to the db object to qu'ery the database + * throws an error if db not initialized. + * example use case assuming you required the module as db + * db.db().find(.... etc + * @return {MongoDBObject} + */ +// exports.db = function() { +// if (DB === null) throw Error('DB Object has not yet been initialized'); +// return DB; +// }; + +/** + * clears all collections in the database calling the callback when done + * @param {Function} done callback indicating the operation is complete + */ +exports.clearDB = function(done) { + // console.log(DB.listCollections().toArray()); + DB.listCollections().toArray().then(function (collections) { + collections.forEach(function (c) { + + DB.collection(c.name).removeMany(); + }); + done(); + }).catch(done); +}; \ No newline at end of file diff --git a/31-2140/header.jpeg b/31-2140/header.jpeg new file mode 100644 index 0000000..53fcfb4 Binary files /dev/null and b/31-2140/header.jpeg differ diff --git a/31-2140/package.json b/31-2140/package.json new file mode 100644 index 0000000..9d76cf4 --- /dev/null +++ b/31-2140/package.json @@ -0,0 +1,21 @@ + +{ + "name": "31-2140", + "version": "0.0.0", + "private": true, + "scripts": { + "start": "nodemon server.js", + "test":"mocha ./tests/quotes.js", + "coverage":"istanbul cover _mocha ./tests/quotes.js" + }, + "dependencies": { + "express": "~4.12.4", + "mongodb": "~2.1", + "consolidate": "~0.14.0", + "swig": "~1.4.2", + "mocha": "~2.3.0", + "supertest": "~1.2.0", + "chai": "~3.5.0", + "istanbul": "~0.4.2" + } +} \ No newline at end of file diff --git a/31-2140/package.json~ b/31-2140/package.json~ new file mode 100644 index 0000000..0757b4b --- /dev/null +++ b/31-2140/package.json~ @@ -0,0 +1,19 @@ +{ + "name": "31-2140", + "version": "1.1.1", + "private": true, + "scripts": { + "start": "node server.js" + }, + "dependencies": { + "body-parser": "~1.12.4", + "cookie-parser": "~1.3.5", + "debug": "~2.2.0", + "jade": "~1.9.2", + "express": "~4.12.4", + "morgan": "~1.5.3", + "mongodb": "~1.4", + "mongoskin": "~1.4.13", + "monk": "~1.0.1" + } +} diff --git a/31-2140/public/app.js~ b/31-2140/public/app.js~ new file mode 100644 index 0000000..00fd4da --- /dev/null +++ b/31-2140/public/app.js~ @@ -0,0 +1,53 @@ +var express = require('express'); +var path = require('path'); +var logger = require('morgan'); +var bodyParser = require('body-parser'); + +var routes = require('./routes/index'); + +var app = express(); + +// view engine setup +app.set('views', path.join(__dirname, 'views')); +app.set('view engine', 'jade'); + +app.use(logger('dev')); +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded()); +app.use(express.static(path.join(__dirname, 'public'))); + +app.use('/', routes); + +/// catch 404 and forwarding to error handler +app.use(function(req, res, next) { + var err = new Error('Not Found'); + err.status = 404; + next(err); +}); + +/// error handlers + +// development error handler +// will print stacktrace +if (app.get('env') === 'development') { + app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: err + }); + }); +} + +// production error handler +// no stacktraces leaked to user +app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: {} + }); +}); + + +module.exports = app; diff --git a/31-2140/public/css/style.css b/31-2140/public/css/style.css new file mode 100644 index 0000000..b6168f4 --- /dev/null +++ b/31-2140/public/css/style.css @@ -0,0 +1,88 @@ +* {box-sizing: border-box;} +html { + height: 100%; +} +body { + position: relative; + width: 100%; + height: 100%; + } + + body { + text-align: center; + font-family: Lato, Arial, sans-serif; + font-size: 100%; + cursor: pointer; + background: hsl(400, 60%, 68%); + display: flex; + align-items: center; + justify-content: center; + } +.quote { + height: 1000px; + + display: flex; + align-items: center; + justify-content: center; + + background-color: #345; + /* https://css-tricks.com/perfect-full-page-background-image/ */ + background: url(../header.jpeg) no-repeat center center fixed; + background-size: cover; + + margin-bottom: 10px; +} +.header h1 { + max-width: 50%; + color: #fff; + text-shadow: 2px 2px rgba(0, 0, 0, 0.3); + font-size: 4em; + font-weight: 200; + font-family: cursive; +} +.author { + margin: 0 auto; +} +.quote { + font-weight: 300; + color: #fff; + text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.2); + font-size: 5ex; + padding: 0; + margin: 0; + max-width: 90%; + } +.quote { + overflow:auto; + margin: 10px auto; + width: 70%; + box-shadow: 1px 1px 5px rgba(49, 21, 4, 0.4); + min-height: 140px; + padding: 20px 20px; +} +.author { + position: absolute; + bottom: 0px; + right: 20px; + font-weight: 300; + font-size: 5ex; + color: #fff; + text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.1); + max-width: 60%; + align-self: flex-end; + } + .post-load-btn { + margin: 0 auto; + display: block; + cursor: pointer; + width: 50%; + font-size: 2em; + background: #3C3C3C; + color: #fff; + border: none; + box-shadow: 1px 1px 5px rgba(49, 21, 4, 0.4); + } + + .post-load-btn:hover { + background-color: #555; + } \ No newline at end of file diff --git a/31-2140/public/css/style.css~ b/31-2140/public/css/style.css~ new file mode 100644 index 0000000..720a551 --- /dev/null +++ b/31-2140/public/css/style.css~ @@ -0,0 +1,40 @@ + html, + body { + position: relative; + width: 100%; + height: 100%; + } + + body { + text-align: center; + font-family: Lato, Arial, sans-serif; + font-size: 100%; + cursor: pointer; + background: hsl(400, 60%, 68%); + display: flex; + align-items: center; + justify-content: center; + } + + .quote { + font-weight: 400; + color: #fff; + text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.2); + font-size: 5ex; + padding: 0; + margin: 0; + line-height: 1.5; + max-width: 90%; + } + + .author { + position: absolute; + bottom: 0px; + right: 20px; + font-weight: 300; + font-size: 5ex; + color: #fff; + text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.1); + max-width: 60%; + align-self: flex-end; + } diff --git a/31-2140/public/error.html b/31-2140/public/error.html new file mode 100644 index 0000000..aa6b610 --- /dev/null +++ b/31-2140/public/error.html @@ -0,0 +1,10 @@ + +
+Looking for some inspiration? Just Tap or Click and we will do the Magic+ +
| t |