From b4cbbd3d904d37de29048e9eed0a11b61a3faf0f Mon Sep 17 00:00:00 2001 From: Benjamin Hetherington Date: Mon, 26 Aug 2019 20:34:49 -0400 Subject: [PATCH 1/6] Initial commit --- .gitignore | 70 ++++++++++++++++++++++++++++++++++++ index.html | 28 --------------- package-lock.json | 13 +++++++ package.json | 3 ++ server.js | 91 ++++++++++++++++++++++++++++++++++++++--------- static/index.html | 68 +++++++++++++++++++++++++++++++++++ static/index.js | 1 + static/style.css | 21 +++++++++++ 8 files changed, 251 insertions(+), 44 deletions(-) create mode 100644 .gitignore delete mode 100755 index.html create mode 100644 package-lock.json create mode 100755 static/index.html create mode 100644 static/index.js create mode 100644 static/style.css diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e2279e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,70 @@ +# VS Code +.vscode/ + +# bundle.js +public/bundle.js + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# next.js build output +.next + +# build directory +dist/ \ No newline at end of file diff --git a/index.html b/index.html deleted file mode 100755 index 37ac8c3..0000000 --- a/index.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - CS4241 Assignment 1 - - - -

Information about [Your name here]

-

- [Self introduction] -

-

- [Major and other information] -

-

- [Other things] -

- -

Experience

-

- Working experience -

- - - diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..533d4a3 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "cr-4241-simple-glitch", + "version": "0.1.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "mime": { + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz", + "integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA==" + } + } +} diff --git a/package.json b/package.json index 1699a50..f8acaa2 100755 --- a/package.json +++ b/package.json @@ -5,5 +5,8 @@ "author": "Charlie Roberts", "scripts": { "start": "node server.js" + }, + "dependencies": { + "mime": "^2.4.4" } } diff --git a/server.js b/server.js index cc39a60..4d35d59 100644 --- a/server.js +++ b/server.js @@ -1,20 +1,79 @@ -const http = require('http'), - fs = require('fs'), - port = 3000 +const fs = require("fs"); +const http = require("http"); +const mime = require("mime"); +const path = require("path"); -let file -fs.readFile( './index.html', function( err, content ) { - file = content -}) +class Server { + /** + * Creates a server that serves files from the specified static directory. If + * a user tries to access the root domain, the specified index file is + * served. + * @param indexFile The index file + * @param staticDir The static file directory + */ + constructor(indexFile = "index.html", staticDir = null) { + this.indexFile = indexFile; + this.staticDir = staticDir; + } + + /** + * Starts the server, listening on the specified port. + * @param port The port to listen on + */ + listen(port) { + const server = http.createServer((request, response) => { + console.log(`${request.method}: ${request.url}`); + const url = request.url.slice(1); + if (url === "") { + this.sendFile(this.indexFile, response); + } else { + this.sendFile(url, response); + } + }); + console.log(`Server listening on port: ${port}...`); + server.listen(port); + } + + /** + * Sends a 404 error to the specified response. + * @param fileName The file name that the user tried to access + * @param response The response to send the 404 error to + */ + send404(fileName, response) { + response.writeHeader(404); + response.end(`404 Error: Could not read file "${fileName}"`); + } + + resolveFile(fileName) { + const baseDir = path.normalize(this.staticDir || ""); + const relativePath = path.normalize(fileName); + const filePath = path.join(baseDir, relativePath); + return filePath; + } -const server = http.createServer( function( request,response ) { - switch( request.url ) { - case '/': - response.end( file, 'utf-8') - break - default: - response.end( '404 Error: File Not Found') + /** + * Sends the file with the specified file name as part of the specified + * response. If there is an error reading the file, a 404 response is sent. + * Files are looked for in the specified static directory if one is specified + * when the server is created. + * @param fileName The file name to send + * @param response The response to send the file to + */ + sendFile(fileName, response) { + const file = this.resolveFile(fileName); + console.log(`Sending ${file}...`); + fs.readFile(file, "utf8", (err, data) => { + // Check if we have successfully read the file + if (err) { + this.send404(fileName, response); + } else { + const mimeType = mime.getType(fileName); + response.writeHeader(200, { "content-type": mimeType }); + response.end(data, "utf8"); + } + }); } -}) +} -server.listen( process.env.PORT || port ) \ No newline at end of file +const server = new Server("index.html", "static"); +server.listen(process.env.PORT || 3000); diff --git a/static/index.html b/static/index.html new file mode 100755 index 0000000..92912f3 --- /dev/null +++ b/static/index.html @@ -0,0 +1,68 @@ + + + + CS4241 Assignment 1 + + + + + +
+

Benjamin Hetherington

+

+ Hello, reader! +

+

+ [Major and other information] +

+

+ [Other things] +

+ +

Technological Experience

+ + +

Work Experience

+ +
+ + + diff --git a/static/index.js b/static/index.js new file mode 100644 index 0000000..a8141d3 --- /dev/null +++ b/static/index.js @@ -0,0 +1 @@ +console.log("Hello, world!"); diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..facd836 --- /dev/null +++ b/static/style.css @@ -0,0 +1,21 @@ +:root { + --text-color: rgba(0, 0, 0, 0.93); +} + +body { + font-family: "Roboto", sans-serif; + color: var(--text-color); +} + +.page { + max-width: 1000px; + padding: 15px; + margin: auto; +} + +h1, +h2, +h3, +h4 { + border-bottom: 2px solid; +} From 4cbeef730b0dd5d82008f0bfdc7b116870e65f2a Mon Sep 17 00:00:00 2001 From: Benjamin Hetherington Date: Mon, 26 Aug 2019 20:36:18 -0400 Subject: [PATCH 2/6] Move server.js into server directory --- package.json | 2 +- server.js => server/server.js | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename server.js => server/server.js (100%) diff --git a/package.json b/package.json index f8acaa2..f5af330 100755 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "WPI CS 4241 first assignment", "author": "Charlie Roberts", "scripts": { - "start": "node server.js" + "start": "node server/server.js" }, "dependencies": { "mime": "^2.4.4" diff --git a/server.js b/server/server.js similarity index 100% rename from server.js rename to server/server.js From 95e32d9bb449cca57a46c6831ece4e678037fc07 Mon Sep 17 00:00:00 2001 From: Benjamin Hetherington Date: Thu, 29 Aug 2019 11:30:51 -0400 Subject: [PATCH 3/6] Update page --- package.json | 2 +- static/index.html | 69 ++++++++++++++++++++++++++++++++++++----------- static/style.css | 26 +++++++++++++++++- 3 files changed, 80 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index f5af330..d4279c7 100755 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "cr-4241-simple-glitch", "version": "0.1.0", "description": "WPI CS 4241 first assignment", - "author": "Charlie Roberts", + "author": "Benjamin Hetherington", "scripts": { "start": "node server/server.js" }, diff --git a/static/index.html b/static/index.html index 92912f3..d1035fe 100755 --- a/static/index.html +++ b/static/index.html @@ -13,26 +13,65 @@

Benjamin Hetherington

- Hello, reader! -

-

- [Major and other information] -

-

- [Other things] + Hello, reader! My name is Benjamin Hetherington, and I am a Computer Science major in the class of 2020 at WPI.

-

Technological Experience

+

Courses

    -
  • HTML: A lot
  • -
  • CSS: Some
  • -
  • Java: A lot
  • -
  • JavaScript: A lot
  • -
  • Ruby: None
  • -
  • Python: A lot
  • -
  • Unit Testing: A lot
  • +
  • CS1102
  • +
  • CS210X
  • +
  • CS2303
  • +
  • CS2223
  • +
  • CS2022
  • +
  • CS2011
  • +
  • CS3013
  • +
  • CS3043
  • +
  • CS3133
  • +
  • CS3733
  • +
  • CS4518
  • +
  • CS4731
+

Technological Experience

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TechnologyExperience
HTMLA lot
CssSome
JavaA lot
JavascriptA lot
RubyNone
PythonA lot
Unit TestingA lot
+

Work Experience

  • diff --git a/static/style.css b/static/style.css index facd836..868cc21 100644 --- a/static/style.css +++ b/static/style.css @@ -1,5 +1,6 @@ :root { --text-color: rgba(0, 0, 0, 0.93); + --primary-accent: rgba(0, 0, 0, 0.3); } body { @@ -17,5 +18,28 @@ h1, h2, h3, h4 { - border-bottom: 2px solid; + border-bottom: 2px solid var(--primary-accent); +} + +table { + border: 2px solid var(--primary-accent); + border-radius: 5px; + border-collapse: collapse; + overflow: hidden; +} + +td { + padding: 2px; + padding-left: 5px; + padding-right: 5px; +} + +thead { + /* background: blue; */ + font-weight: bold; + border-bottom: 2px solid var(--primary-accent); +} + +tbody { + /* background: red; */ } From 9bf926ac9ae568017b0c94aaeb9f8f341e0d0978 Mon Sep 17 00:00:00 2001 From: Benjamin Hetherington Date: Thu, 29 Aug 2019 11:37:12 -0400 Subject: [PATCH 4/6] Update README --- README.md | 77 ++++------------------------------------------- static/index.html | 2 ++ 2 files changed, 8 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 4c7f4a8..e346ecf 100644 --- a/README.md +++ b/README.md @@ -1,77 +1,12 @@ -Assignment 1 - Hello World: Basic Deployment w/ Git, GitHub, Glitch -=== +# a1-bwhetherington -*DUE: Thursday, August 29th by 11:59 AM (before the start of class!)* - -This assignment is a "warm-up" exercise. -You will simply deploy the starting Web site that you will use this term to [Glitch](http://www.glitch.com/). - -Treat this assignment as a chance to get up to speed on Git, GitHub, and Glitch. -If you already know these, great. -However, if you're new to them, spend several hours practicing, experimenting, and reading documentation. -In other words, don't just get your website up and done. You will need skills with these tools throughout the rest of the course. - -Assignment details ---- - -Do the following to complete this assignment: - -1. Fork the starting project code in GitHub. This repo contains: - * the server code, `server.js` - * A starting `index.html` file that you will edit as described below - * A package.json file that helps configure Glitch - * This README -2. Edit `index.html` to show the following information about you: - * your name and class at WPI (e.g. class of 2020) Note: Do not put any contact or personal information that you do not potentially want other people outside of this class to see. - * your major(s) and minor(s) - * previous computer science courses that you have taken at WPI - * your experience with the following technologies and methods (none, some, a lot) - * HTML - * CSS - * Java - * JavaScript - * Ruby - * Python - * unit testing -3. Test your project to make sure that when someone goes to your main page, it displays correctly. You can do this locally by simply running `node server.js` from within the assignment directory. - -4. Modify the README file according to the specification below. -5. Commit and push all your changes to GitHub. -6. Deploy your project to Glitch. You can do this by [importing the repo from GitHub](https://medium.com/glitch/import-code-from-anywhere-83fb60ea4875) -7. Ensure that your project has the proper naming scheme (guide follows) so we can find it. -8. Create and submit a Pull Request to the original repo. - -Naming and URL Scheme ---- - -You must use a consistent naming scheme for all projects in this course. -If we can't find it, we can't grade it. - -By default Glitch often assigns your application a random name. To change it, click on the project dropdown menu in the upper left corner of Glitch. You will then see an additional text field displaying the project name in the resulting menu; click here to edit the name. - -The name scheme should be `a1-yourGitHubUsername`. -The `a1` will need to be updated to `a2`, `a3`, and so on in future projects. - -Resources ---- - -If you need a JavaScript/HTML/CSS refresher, see [Technology Fundamentals by Scott Murray](http://chimera.labs.oreilly.com/books/1230000000345/ch03.html#_html) and/or [JavaScript Codeacademy](https://www.codecademy.com/en/tracks/javascript). - -If you need a Git/GitHub refreseher, see [GitHub Bootcamp](https://help.github.com/categories/bootcamp/), the [GitHub Guides](https://guides.github.com/) (especially the ones on Hello World, and Understanding the GitHub Flow, and Forking Projects), and [CodeSchool's Try Git Course](https://www.codeschool.com/courses/try-git). - -Sample Readme (delete the above when you're ready to submit, and modify the below so with your links and descriptions) ---- - -Charlie Roberts -http://charlieroberts-a1.glitch.me - -This project shows ... +Benjamin Hetherington +http://a1-bwhetherington.glitch.me ## Technical Achievements -- **Proved P=NP**: Using a combination of... -- **Solved AI**: ... -### Design Achievements -- **Re-vamped Apple's Design Philosophy**: Shown in `style.css`, the code... +- **Custom Server Script:** I solved the problems with the original server script by writing my own from scratch. In addition, it restricts access to only files in the static directory to ensure that people cannot access other files on the server. +## Design Achievements +- **Custom CSS:** I wrote my own CSS for the website. It is admittedly quite simple, but it is something. diff --git a/static/index.html b/static/index.html index d1035fe..392c4ce 100755 --- a/static/index.html +++ b/static/index.html @@ -17,6 +17,7 @@

    Benjamin Hetherington

    Courses

    +

    Below are the CS courses I have taken at WPI, as of writing this page (August 2019):

    • CS1102
    • CS210X
    • @@ -73,6 +74,7 @@

      Technological Experience

      Work Experience

      + Below is my work history as of writing this page (August 2019):
      • Amazon Web Services

        From 4f017add6559d0d01b1f9e364c9c9f5d3ce85a4f Mon Sep 17 00:00:00 2001 From: Benjamin Hetherington Date: Thu, 29 Aug 2019 11:37:35 -0400 Subject: [PATCH 5/6] Remove index.js --- static/index.html | 1 - static/index.js | 1 - 2 files changed, 2 deletions(-) delete mode 100644 static/index.js diff --git a/static/index.html b/static/index.html index 392c4ce..059f258 100755 --- a/static/index.html +++ b/static/index.html @@ -104,6 +104,5 @@

        Sense Labs

- diff --git a/static/index.js b/static/index.js deleted file mode 100644 index a8141d3..0000000 --- a/static/index.js +++ /dev/null @@ -1 +0,0 @@ -console.log("Hello, world!"); From ffb9c5df479110f66e18362cf0d6b7cec13472ec Mon Sep 17 00:00:00 2001 From: Benjamin Hetherington Date: Thu, 29 Aug 2019 11:46:15 -0400 Subject: [PATCH 6/6] Update README --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index e346ecf..e776539 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # a1-bwhetherington -Benjamin Hetherington -http://a1-bwhetherington.glitch.me +[Benjamin Hetherington](http://a1-bwhetherington.glitch.me) ## Technical Achievements