From 0e3bb39710e4f9e64bed9ab113fcb363aa9ef266 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Thu, 18 Mar 2021 09:09:05 -0500 Subject: Start Hw5 --- csci4131/hw5/strap012_hw5/client/addContact.html | 113 +++++++++++++++++++++++ csci4131/hw5/strap012_hw5/client/contacts.html | 43 +++++++++ csci4131/hw5/strap012_hw5/client/index.html | 27 ++++++ csci4131/hw5/strap012_hw5/client/stock.html | 99 ++++++++++++++++++++ csci4131/hw5/strap012_hw5/contacts.json | 22 +++++ csci4131/hw5/strap012_hw5/createServer.js | 56 +++++++++++ csci4131/hw5/strap012_hw5/package.json | 11 +++ 7 files changed, 371 insertions(+) create mode 100755 csci4131/hw5/strap012_hw5/client/addContact.html create mode 100755 csci4131/hw5/strap012_hw5/client/contacts.html create mode 100755 csci4131/hw5/strap012_hw5/client/index.html create mode 100755 csci4131/hw5/strap012_hw5/client/stock.html create mode 100755 csci4131/hw5/strap012_hw5/contacts.json create mode 100755 csci4131/hw5/strap012_hw5/createServer.js create mode 100755 csci4131/hw5/strap012_hw5/package.json (limited to 'csci4131') diff --git a/csci4131/hw5/strap012_hw5/client/addContact.html b/csci4131/hw5/strap012_hw5/client/addContact.html new file mode 100755 index 0000000..12bfaa2 --- /dev/null +++ b/csci4131/hw5/strap012_hw5/client/addContact.html @@ -0,0 +1,113 @@ + + + + + + + + + + + + + +

+ +
+
+


+
+ +
+
+
+
+
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name +
+ +
+
Category +
+ +
+
Location +
+ +
+
Contact Information +
+ +
+
Email +
+ +
+
Website Name +
+ +
+
Website URL +
+ +
+
+ +
+
+
+
+
+
+
+ + diff --git a/csci4131/hw5/strap012_hw5/client/contacts.html b/csci4131/hw5/strap012_hw5/client/contacts.html new file mode 100755 index 0000000..e24ca84 --- /dev/null +++ b/csci4131/hw5/strap012_hw5/client/contacts.html @@ -0,0 +1,43 @@ + + + + + + + + + + +

+ +
+ + + + + + + + + + + + +
NameCategoryLocationContact InformationEmailWebsite
(URL)
+
+ + + diff --git a/csci4131/hw5/strap012_hw5/client/index.html b/csci4131/hw5/strap012_hw5/client/index.html new file mode 100755 index 0000000..44c5d0f --- /dev/null +++ b/csci4131/hw5/strap012_hw5/client/index.html @@ -0,0 +1,27 @@ + + + + + + + + + + +


+
+
+
Welcome to Contact Management
+
+
+ + diff --git a/csci4131/hw5/strap012_hw5/client/stock.html b/csci4131/hw5/strap012_hw5/client/stock.html new file mode 100755 index 0000000..91f8493 --- /dev/null +++ b/csci4131/hw5/strap012_hw5/client/stock.html @@ -0,0 +1,99 @@ + + + + + + + + + + + + + +

+ +
+
+
Welcome to Stock Page
+
+
+ +
+
+
+ + + + + + + + + + +
Company +
+ +
+
+ +
+
+
+
+ +
+
+
+ +
+ + + + + + + + +
Company-MetaDataStock-Info
+
+ + + + diff --git a/csci4131/hw5/strap012_hw5/contacts.json b/csci4131/hw5/strap012_hw5/contacts.json new file mode 100755 index 0000000..54149e8 --- /dev/null +++ b/csci4131/hw5/strap012_hw5/contacts.json @@ -0,0 +1,22 @@ +{ + "contacts": [ + { + "name": "President Joan T.A. Gabel", + "category": "Academic", + "location": "202 Morrill Hall\r\n100 Church Street SE\r\nMinneapolis, MN 55455", + "contact": "President of the University of Minnesota System", + "email": "upres@umn.edu", + "website_name": "Home Page", + "website_url": "https://president.umn.edu/" + }, + { + "name": "Professor Dan Challou", + "category": "Academic", + "location": "383 Shepherd Laboratory\r\n100 Union Street SE\r\nMinneapolis, MN 55455", + "contact": "Professor of CSCI 4131 - Internet Programming", + "email": "chal0006@umn.edu", + "website_name": "Course Home Page", + "website_url": "https://canvas.umn.edu/courses/217376" + } + ] +} diff --git a/csci4131/hw5/strap012_hw5/createServer.js b/csci4131/hw5/strap012_hw5/createServer.js new file mode 100755 index 0000000..01f1f08 --- /dev/null +++ b/csci4131/hw5/strap012_hw5/createServer.js @@ -0,0 +1,56 @@ + +const http = require('http'); +const url = require('url'); +const fs = require('fs'); +const qs = require('querystring'); + +const port = 9001; +http.createServer(function (req, res) { + var q = url.parse(req.url, true); + var filename = "." + q.pathname; + if(req.url === '/'){ + indexPage(req,res); + } + else if (req.url === '/index.html') { + indexPage(req, res, '/index.html'); + } + else if (req.url === '/contacts.html') { + indexPage(req, res, '/contacts.html'); + } + else if (req.url === '/addContact.html') { + indexPage(req, res, '/addContact.html'); + } + else if (req.url === '/stock.html') { + jsonSock(req, res, '/stock.html'); + } + else{ + res.writeHead(404, {'Content-Type': 'text/html'}); + return res.end("404 Not Found"); + } +}).listen(port); + + +function indexPage(req, res, file) { + fs.readFile('client' + file, function(err, html) { + if(err) { + throw err; + } + res.statusCode = 200; + res.setHeader('Content-type', 'text/html'); + res.write(html); + res.end(); + }); +} + +function jsonSock(req, res, file) { + fs.readFile('client/' + file, function (err, json) { + if (err) { + throw err; + } + res.statusCode = 200; + res.setHeader('Content-type', 'text/json'); + res.write(json); + res.end(); + }); +} + diff --git a/csci4131/hw5/strap012_hw5/package.json b/csci4131/hw5/strap012_hw5/package.json new file mode 100755 index 0000000..90f2542 --- /dev/null +++ b/csci4131/hw5/strap012_hw5/package.json @@ -0,0 +1,11 @@ +{ + "name": "strap012_hw5", + "version": "1.0.0", + "description": "Assignment 5", + "main": "createServer.js", + "scripts": { + "test": "node createServer.js" + }, + "author": "strap012", + "license": "ISC" +} -- cgit v1.2.3