From 6f4b2bd73bc6d45491b7050b51f7d7a09a02c44c Mon Sep 17 00:00:00 2001 From: rabGIT Date: Mon, 8 May 2017 09:50:04 -0700 Subject: [PATCH 1/2] initial commit --- .gitignore | 1 + README.md | 2 + app.js | 46 ++++++++++++++++++ bin/www | 90 ++++++++++++++++++++++++++++++++++++ npm-debug.log | 45 ++++++++++++++++++ package.json | 17 +++++++ public/stylesheets/style.css | 8 ++++ routes/index.js | 9 ++++ views/error.hbs | 3 ++ views/index.hbs | 2 + views/layout.hbs | 38 +++++++++++++++ 11 files changed, 261 insertions(+) create mode 100644 .gitignore create mode 100644 app.js create mode 100755 bin/www create mode 100644 npm-debug.log create mode 100644 package.json create mode 100644 public/stylesheets/style.css create mode 100644 routes/index.js create mode 100644 views/error.hbs create mode 100644 views/index.hbs create mode 100644 views/layout.hbs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ccbe46 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/node_modules/ diff --git a/README.md b/README.md index a8725b5..c6f1f20 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # assignment_css_garden_of_good_and_evil Create a CSS garden that adapts to your whims. + +Richard Bell diff --git a/app.js b/app.js new file mode 100644 index 0000000..2e8ef72 --- /dev/null +++ b/app.js @@ -0,0 +1,46 @@ +var express = require('express'); +var path = require('path'); +var favicon = require('serve-favicon'); +var logger = require('morgan'); +var cookieParser = require('cookie-parser'); +var bodyParser = require('body-parser'); + +var index = require('./routes/index'); + + +var app = express(); + +// view engine setup +app.set('views', path.join(__dirname, 'views')); +app.set('view engine', 'hbs'); + +// uncomment after placing your favicon in /public +//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); +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('/', index); + + +// 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 handler +app.use(function(err, req, res, next) { + // set locals, only providing error in development + res.locals.message = err.message; + res.locals.error = req.app.get('env') === 'development' ? err : {}; + + // render the error page + res.status(err.status || 500); + res.render('error'); +}); + +module.exports = app; diff --git a/bin/www b/bin/www new file mode 100755 index 0000000..f5016d8 --- /dev/null +++ b/bin/www @@ -0,0 +1,90 @@ +#!/usr/bin/env node + +/** + * Module dependencies. + */ + +var app = require('../app'); +var debug = require('debug')('assignment-css-garden-of-good-and-evil:server'); +var http = require('http'); + +/** + * Get port from environment and store in Express. + */ + +var port = normalizePort(process.env.PORT || '3000'); +app.set('port', port); + +/** + * Create HTTP server. + */ + +var server = http.createServer(app); + +/** + * Listen on provided port, on all network interfaces. + */ + +server.listen(port); +server.on('error', onError); +server.on('listening', onListening); + +/** + * Normalize a port into a number, string, or false. + */ + +function normalizePort(val) { + var port = parseInt(val, 10); + + if (isNaN(port)) { + // named pipe + return val; + } + + if (port >= 0) { + // port number + return port; + } + + return false; +} + +/** + * Event listener for HTTP server "error" event. + */ + +function onError(error) { + if (error.syscall !== 'listen') { + throw error; + } + + var bind = typeof port === 'string' + ? 'Pipe ' + port + : 'Port ' + port; + + // handle specific listen errors with friendly messages + switch (error.code) { + case 'EACCES': + console.error(bind + ' requires elevated privileges'); + process.exit(1); + break; + case 'EADDRINUSE': + console.error(bind + ' is already in use'); + process.exit(1); + break; + default: + throw error; + } +} + +/** + * Event listener for HTTP server "listening" event. + */ + +function onListening() { + var addr = server.address(); + var bind = typeof addr === 'string' + ? 'pipe ' + addr + : 'port ' + addr.port; + debug('Listening on ' + bind); +} diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 0000000..b278374 --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,45 @@ +0 info it worked if it ends with ok +1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ] +2 info using npm@4.1.2 +3 info using node@v7.7.4 +4 verbose run-script [ 'prestart', 'start', 'poststart' ] +5 info lifecycle assignment-css-garden-of-good-and-evil@0.0.0~prestart: assignment-css-garden-of-good-and-evil@0.0.0 +6 silly lifecycle assignment-css-garden-of-good-and-evil@0.0.0~prestart: no script for prestart, continuing +7 info lifecycle assignment-css-garden-of-good-and-evil@0.0.0~start: assignment-css-garden-of-good-and-evil@0.0.0 +8 verbose lifecycle assignment-css-garden-of-good-and-evil@0.0.0~start: unsafe-perm in lifecycle true +9 verbose lifecycle assignment-css-garden-of-good-and-evil@0.0.0~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/rabell/Documents/Development/viking/express/assignment_css_garden_of_good_and_evil/node_modules/.bin:~/.npm-packages/bin:/Users/rabell/google-cloud-sdk/bin:/Users/rabell/.rvm/gems/ruby-2.3.3/bin:/Users/rabell/.rvm/gems/ruby-2.3.3@global/bin:/Users/rabell/.rvm/rubies/ruby-2.3.3/bin:/Users/rabell/anaconda/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/ImageMagick/bin:/usr/local/MacGPG2/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/rabell/.rvm/bin +10 verbose lifecycle assignment-css-garden-of-good-and-evil@0.0.0~start: CWD: /Users/rabell/Documents/Development/viking/express/assignment_css_garden_of_good_and_evil +11 silly lifecycle assignment-css-garden-of-good-and-evil@0.0.0~start: Args: [ '-c', 'node ./bin/www' ] +12 silly lifecycle assignment-css-garden-of-good-and-evil@0.0.0~start: Returned: code: 1 signal: null +13 info lifecycle assignment-css-garden-of-good-and-evil@0.0.0~start: Failed to exec start script +14 verbose stack Error: assignment-css-garden-of-good-and-evil@0.0.0 start: `node ./bin/www` +14 verbose stack Exit status 1 +14 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:279:16) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at EventEmitter.emit (events.js:194:7) +14 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at ChildProcess.emit (events.js:194:7) +14 verbose stack at maybeClose (internal/child_process.js:899:16) +14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5) +15 verbose pkgid assignment-css-garden-of-good-and-evil@0.0.0 +16 verbose cwd /Users/rabell/Documents/Development/viking/express/assignment_css_garden_of_good_and_evil +17 error Darwin 16.5.0 +18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "start" +19 error node v7.7.4 +20 error npm v4.1.2 +21 error code ELIFECYCLE +22 error assignment-css-garden-of-good-and-evil@0.0.0 start: `node ./bin/www` +22 error Exit status 1 +23 error Failed at the assignment-css-garden-of-good-and-evil@0.0.0 start script 'node ./bin/www'. +23 error Make sure you have the latest version of node.js and npm installed. +23 error If you do, this is most likely a problem with the assignment-css-garden-of-good-and-evil package, +23 error not with npm itself. +23 error Tell the author that this fails on your system: +23 error node ./bin/www +23 error You can get information on how to open an issue for this project with: +23 error npm bugs assignment-css-garden-of-good-and-evil +23 error Or if that isn't available, you can get their info via: +23 error npm owner ls assignment-css-garden-of-good-and-evil +23 error There is likely additional logging output above. +24 verbose exit [ 1, true ] diff --git a/package.json b/package.json new file mode 100644 index 0000000..e72625d --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "assignment-css-garden-of-good-and-evil", + "version": "0.0.0", + "private": true, + "scripts": { + "start": "node ./bin/www" + }, + "dependencies": { + "body-parser": "~1.17.1", + "cookie-parser": "~1.4.3", + "debug": "~2.6.3", + "express": "~4.15.2", + "hbs": "~4.0.1", + "morgan": "~1.8.1", + "serve-favicon": "~2.4.2" + } +} diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css new file mode 100644 index 0000000..9453385 --- /dev/null +++ b/public/stylesheets/style.css @@ -0,0 +1,8 @@ +body { + padding: 50px; + font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; +} + +a { + color: #00B7FF; +} diff --git a/routes/index.js b/routes/index.js new file mode 100644 index 0000000..ecca96a --- /dev/null +++ b/routes/index.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.render('index', { title: 'Express' }); +}); + +module.exports = router; diff --git a/views/error.hbs b/views/error.hbs new file mode 100644 index 0000000..0659765 --- /dev/null +++ b/views/error.hbs @@ -0,0 +1,3 @@ +

{{message}}

+

{{error.status}}

+
{{error.stack}}
diff --git a/views/index.hbs b/views/index.hbs new file mode 100644 index 0000000..1f308fd --- /dev/null +++ b/views/index.hbs @@ -0,0 +1,2 @@ +

{{title}}

+

Welcome to {{title}}

diff --git a/views/layout.hbs b/views/layout.hbs new file mode 100644 index 0000000..194b56b --- /dev/null +++ b/views/layout.hbs @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + {{title}} + + + + +
+ {{{body}}} +
+ + + + + + + + + + From 16b9b04e153e83e11292424aefa6cb18d926a463 Mon Sep 17 00:00:00 2001 From: rabGIT Date: Mon, 8 May 2017 11:36:06 -0700 Subject: [PATCH 2/2] cookie based config --- public/stylesheets/style.css | 14 ++++++++ routes/index.js | 23 ++++++++++++- views/index.hbs | 63 ++++++++++++++++++++++++++++++++++-- views/layout.hbs | 26 ++++++++++++++- 4 files changed, 122 insertions(+), 4 deletions(-) diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index 9453385..9aa107a 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -6,3 +6,17 @@ body { a { color: #00B7FF; } + +form { + padding: 10px; + border: 1px; + border-color: black; + border-radius: 5px; + border-style: solid;; +} + +@keyframes flash { + 0% { opacity: 1; } + 50% { opacity: .1; } + 100% { opacity: 1; } +} diff --git a/routes/index.js b/routes/index.js index ecca96a..ff18b51 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,9 +1,30 @@ var express = require('express'); var router = express.Router(); + /* GET home page. */ router.get('/', function(req, res, next) { - res.render('index', { title: 'Express' }); + let morals = req.cookies.morals; + if (!morals) morals = 'good'; + console.log(req.cookies); + let flash = req.cookies.insanity ? (1 / parseInt(req.cookies.insanity)) : 0; + if (flash == 1) flash = 0; + res.render('index', { title: 'CSS Garden of Good and Evil', + morals: (morals === 'good'), + favFood: req.cookies.favFood || 'Favorite Food', + favColor: req.cookies.favColor || 'black', + flash: flash.toString() + 's', + insanity: req.cookies.insanity || 1 + }); +}); + +/* Post home page. */ +router.post('/', function(req, res, next) { + res.cookie("morals", req.body.morals); + res.cookie("favFood", req.body.favFood || req.cookies.favFood); + res.cookie("favColor", req.body.favColor || req.cookies.favColor); + res.cookie("insanity", req.body.insanity || req.cookies.insanity) + res.redirect("back"); }); module.exports = router; diff --git a/views/index.hbs b/views/index.hbs index 1f308fd..fd50c1d 100644 --- a/views/index.hbs +++ b/views/index.hbs @@ -1,2 +1,61 @@ -

{{title}}

-

Welcome to {{title}}

+

{{title}}

+

Welcome to {{title}}

+ +
+
+
+
+ +
+
+ +
+
+ + + +
+
+ + +
+
+ + +
+ + +
+
+
+
+
+
+ {{#if morals}} +

Good

+

+ In its most general context of the study of morality, ethics, religion and philosophy, the good often refers to and denotes that conduct which is to be preferred and prescribed by society and its social constituents as beneficial and useful to the social + needs of society and its preferred conventions. The specific meaning and etiology of the meaning and use of the 'good' and its associated translations among ancient and contemporary languages has varied substantially in its inflected meaning depending + of circumstances of place, history, religious context and philosophical context. +

+ {{else}} +

Evil

+

Evil, in a general context, is the absence or opposite of that which is described as being good. Often, evil denotes profound immorality. In certain religious contexts, evil has been described as a supernatural force. Definitions of evil vary, + as does the analysis of its motives. However, elements that are commonly associated with evil involve unbalanced behavior involving expediency, selfishness, ignorance, or neglect.

+ + {{/if}} +
+
diff --git a/views/layout.hbs b/views/layout.hbs index 194b56b..e7687bb 100644 --- a/views/layout.hbs +++ b/views/layout.hbs @@ -20,11 +20,32 @@ {{title}} +
- {{{body}}} + {{{body}}}
@@ -33,6 +54,9 @@ +