├── .nvmrc ├── .gitignore ├── README.md ├── app ├── script.js ├── styles.css └── index.html ├── package.json ├── gulpfile.js └── api └── index.js /.nvmrc: -------------------------------------------------------------------------------- 1 | iojs -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | node_modules 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jacob.reviews 2 | 3 | Talk to jr about jacob. -------------------------------------------------------------------------------- /app/script.js: -------------------------------------------------------------------------------- 1 | fetch('/api') 2 | .then(function (res) { 3 | return res.json(); 4 | }) 5 | .then(writeQuote); 6 | 7 | function writeQuote(data) { 8 | document.querySelector('.js-quote').textContent = data.review; 9 | document.querySelector('.js-cite').textContent = '—' + data.name; 10 | } 11 | -------------------------------------------------------------------------------- /app/styles.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | height: 100%; 3 | max-height: 1000px; 4 | } 5 | 6 | body { 7 | display: flex; 8 | align-items: center; 9 | justify-content: center; 10 | 11 | font-family: 'Open Sans', sans-serif; 12 | text-align: center; 13 | 14 | background-color: #1B1B70; 15 | color: #EB0E82; 16 | } 17 | 18 | blockquote p { 19 | margin-top: 0; 20 | margin-bottom: 0.5em; 21 | 22 | font-size: 4em; 23 | } 24 | 25 | blockquote cite { 26 | font-size: 1.5em; 27 | } 28 | 29 | @media screen and (max-width: 500px) { 30 | body { 31 | font-size: 8pt; 32 | } 33 | 34 | .github-banner { 35 | display: none; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jacob.reviews", 3 | "version": "1.0.0", 4 | "description": "review jacob", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/callumacrae/jacob.reviews" 12 | }, 13 | "author": "Callum Macrae ", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/callumacrae/jacob.reviews/issues" 17 | }, 18 | "homepage": "https://github.com/callumacrae/jacob.reviews", 19 | "devDependencies": { 20 | "browser-sync": "^2.6.5", 21 | "chalk": "^1.0.0", 22 | "gulp": "^3.8.11", 23 | "nodemon": "^1.3.7" 24 | }, 25 | "dependencies": { 26 | "bluebird": "^2.9.24", 27 | "body-parser": "^1.12.3", 28 | "express": "^4.12.3", 29 | "minimist": "^1.1.1", 30 | "mongodb": "^2.0.28" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const browserSync = require('browser-sync'); 4 | const chalk = require('chalk'); 5 | const gulp = require('gulp'); 6 | const nodemon = require('nodemon'); 7 | 8 | gulp.task('run', function (done) { 9 | function doneOnce() { 10 | done(); 11 | doneOnce = function () {}; 12 | } 13 | 14 | nodemon('--watch api ./api --port 3025') 15 | .on('start', function () { 16 | console.log(chalk.grey('App has started')); 17 | doneOnce(); 18 | }) 19 | .on('restart', function () { 20 | console.log(chalk.grey('App restarting')); 21 | }) 22 | .on('crash', function () { 23 | console.log(chalk.grey('App has crashed')); 24 | }); 25 | }); 26 | 27 | gulp.task('default', ['run'], function () { 28 | let files = [ 29 | './app/*' 30 | ]; 31 | 32 | browserSync.init(files, { 33 | proxy: 'http://localhost:3025/' 34 | }); 35 | 36 | gulp.watch('./app/assets/css/*.css', ['css']); 37 | gulp.watch('./app/assets/js/*.js', ['js']); 38 | }); 39 | -------------------------------------------------------------------------------- /app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | jacob.reviews 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |

Single page web apps don't work

16 |
17 | —Jacob Thompson 18 |
19 |
20 | 21 | 22 | 23 | 24 | Fork me on GitHub 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /api/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const argv = require('minimist')(process.argv.slice(2)); 4 | const bodyParser = require('body-parser'); 5 | const express = require('express'); 6 | const app = express(); 7 | const MongoClient = require('mongodb').MongoClient; 8 | const Promise = require('bluebird'); 9 | 10 | app.use(express.static('app')); 11 | 12 | let collection; 13 | 14 | let mongoConnect = Promise.promisify(MongoClient.connect); 15 | let mongoPromise = mongoConnect('mongodb://localhost:27017/reviews') 16 | .then(function (db) { 17 | collection = db.collection('jacobReviews'); 18 | }); 19 | 20 | app.get('/api', sendData); 21 | function sendData(req, res) { 22 | collection.find().sort({ _id: -1 }).limit(1).toArray(function (err, data) { 23 | if (err) { 24 | return res.status(500).send(err); 25 | } 26 | 27 | res.send(data[0]); 28 | }); 29 | } 30 | 31 | app.post('/api', bodyParser.json(), function (req, res) { 32 | let data = { 33 | name: req.body.name, 34 | review: req.body.review 35 | }; 36 | 37 | collection.insert(data, function () { 38 | sendData(req, res); 39 | }); 40 | }); 41 | 42 | let serverPromise = Promise.promisify(app.listen.bind(app))(argv.port || 3000); 43 | 44 | Promise.join(mongoPromise, serverPromise) 45 | .then(function () { 46 | console.log('Server started'); 47 | }) 48 | .catch(function () { 49 | console.log('Failed to start :('); 50 | process.exit(1); 51 | }); 52 | --------------------------------------------------------------------------------