Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Youssuf Radi 31-2140 #45

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions 31-2140/app.js
Original file line number Diff line number Diff line change
@@ -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;
58 changes: 58 additions & 0 deletions 31-2140/app.js~
Original file line number Diff line number Diff line change
@@ -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;
44 changes: 44 additions & 0 deletions 31-2140/db.js
Original file line number Diff line number Diff line change
@@ -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);
};
Binary file added 31-2140/header.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions 31-2140/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
19 changes: 19 additions & 0 deletions 31-2140/package.json~
Original file line number Diff line number Diff line change
@@ -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"
}
}
53 changes: 53 additions & 0 deletions 31-2140/public/app.js~
Original file line number Diff line number Diff line change
@@ -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;
88 changes: 88 additions & 0 deletions 31-2140/public/css/style.css
Original file line number Diff line number Diff line change
@@ -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;
}
Loading