Added work from my other class repositories before deletion

This commit is contained in:
2017-11-29 10:28:24 -08:00
parent cb0b5f4d25
commit 5ea24c81b5
198 changed files with 739603 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
{
"name": "CS290_Week7",
"version": "1.0.0",
"description": "Week 7 content.",
"main": "week7.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Corwin Perren",
"license": "ISC",
"dependencies": {
"body-parser": "^1.15.0",
"express": "^4.13.2",
"express-handlebars": "^2.0.1",
"express-session": "^1.11.3",
"mysql": "^2.8.0"
}
}

View File

@@ -0,0 +1 @@
<h1>Error 404 - Page Is Nowhere to be Found</h1>

View File

@@ -0,0 +1 @@
<h1>Error 500 - Something Has Gone Terribly Wrong</h1>

View File

@@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>CS 290 Get and Post Checker - Week 7</title>
</head>
<body>
{{{body}}}
</body>
</html>

View File

@@ -0,0 +1,7 @@
<h1>{{StatusHeader}}</h1>
<h2>Query Parameters</h2>
<ul>
{{#each query_data}}
<li>{{this.name}}: {{this.value}}
{{/each}}
</ul>

View File

@@ -0,0 +1,14 @@
<h1>{{StatusHeader}}</h1>
<h2>Query Parameters</h2>
<ul>
{{#each query_data}}
<li>{{this.name}}: {{this.value}}
{{/each}}
</ul>
<h2>Body Property Values</h2>
<ul>
{{#each body_data}}
<li>{{this.name}}: {{this.value}}
{{/each}}
</ul>

View File

@@ -0,0 +1,69 @@
//Base code copied with permission from https://github.com/wolfordj/CS290-Server-Side-Examples
var express = require('express');
var app = express();
var handlebars = require('express-handlebars').create({defaultLayout:'main'});
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
app.set('port', 3000);
function get_data_array(data){
params = [];
for(par in data){
params.push({'name':par, 'value':data[par]});
}
return params;
}
function generateContext_GET(req){
var dynamic_page_contents = {};
dynamic_page_contents.StatusHeader = req.method + " Request Received";
dynamic_page_contents.query_data = get_data_array(req.query);
return dynamic_page_contents;
}
function generateContext_POST(req){
var dynamic_page_contents = {};
dynamic_page_contents.StatusHeader = req.method + " Request Received";
dynamic_page_contents.query_data = get_data_array(req.query);
dynamic_page_contents.body_data = get_data_array(req.body);
return dynamic_page_contents;
}
function my_get(req,res){
res.render('week7_GET', generateContext_GET(req));
}
app.get('/', my_get);
app.post('/', function(req,res){
res.render('week7_POST', generateContext_POST(req));
});
app.use(function(req,res){
res.status(404);
res.render('404');
});
app.use(function(err, req, res, next){
console.error(err.stack);
res.type('plain/text');
res.status(500);
res.render('500');
});
function on_listen(){
console.log('Express started on http://localhost:' + app.get('port') + '; press Ctrl-C to terminate.');
}
app.listen(app.get('port'), on_listen);