From 5e7739a8204f500240191a2c11a4f2eb3b006d4c Mon Sep 17 00:00:00 2001
From: CJACOBSON32 <34342644+CJACOBSON32@users.noreply.github.com>
Date: Thu, 1 Sep 2022 13:17:53 -0400
Subject: [PATCH 01/12] Added boilerplate .gitignore and ran npm install
---
.gitignore | 49 +++++++++++++++++++++++++++++++++++
.idea/.gitignore | 5 ++++
.idea/cs4241_assignment_2.iml | 12 +++++++++
.idea/modules.xml | 8 ++++++
.idea/vcs.xml | 6 +++++
package-lock.json | 30 +++++++++++++++++++++
6 files changed, 110 insertions(+)
create mode 100644 .gitignore
create mode 100644 .idea/.gitignore
create mode 100644 .idea/cs4241_assignment_2.iml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/vcs.xml
create mode 100644 package-lock.json
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8cb80ba
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,49 @@
+node_modules/
+
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# SonarLint plugin
+.idea/sonarlint/
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..b58b603
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,5 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/cs4241_assignment_2.iml b/.idea/cs4241_assignment_2.iml
new file mode 100644
index 0000000..0c8867d
--- /dev/null
+++ b/.idea/cs4241_assignment_2.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..eb9b380
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..485bd31
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,30 @@
+{
+ "name": "cs4241_assignment_2",
+ "lockfileVersion": 2,
+ "requires": true,
+ "packages": {
+ "": {
+ "dependencies": {
+ "mime": "^2.4.4"
+ }
+ },
+ "node_modules/mime": {
+ "version": "2.6.0",
+ "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz",
+ "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==",
+ "bin": {
+ "mime": "cli.js"
+ },
+ "engines": {
+ "node": ">=4.0.0"
+ }
+ }
+ },
+ "dependencies": {
+ "mime": {
+ "version": "2.6.0",
+ "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz",
+ "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg=="
+ }
+ }
+}
From 722148872f6a3d6c49ec8077d3c977c3600cb572 Mon Sep 17 00:00:00 2001
From: chjm6
Date: Sun, 4 Sep 2022 14:51:30 -0400
Subject: [PATCH 02/12] Added some npm dependencies, switched to typescript,
and reformatted code
---
.idea/compiler.xml | 6 ++
.idea/jsLibraryMappings.xml | 6 ++
package-lock.json | 66 ++++++++++++++++++-
package.json | 7 +-
public/index.html | 64 +++++++++---------
public/js/scripts.js | 3 +-
public/js/scripts.ts | 3 +
server.improved.js | 127 ++++++++++++++++--------------------
server.improved.ts | 67 +++++++++++++++++++
9 files changed, 241 insertions(+), 108 deletions(-)
create mode 100644 .idea/compiler.xml
create mode 100644 .idea/jsLibraryMappings.xml
create mode 100644 public/js/scripts.ts
create mode 100644 server.improved.ts
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..1a2fb33
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml
new file mode 100644
index 0000000..d23208f
--- /dev/null
+++ b/.idea/jsLibraryMappings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index 485bd31..4fcb912 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -5,9 +5,35 @@
"packages": {
"": {
"dependencies": {
- "mime": "^2.4.4"
+ "mime": "^2.4.4",
+ "typescript": "^4.8.2"
+ },
+ "devDependencies": {
+ "@types/filesystem": "^0.0.32",
+ "@types/node": "^18.7.14"
+ }
+ },
+ "node_modules/@types/filesystem": {
+ "version": "0.0.32",
+ "resolved": "https://registry.npmjs.org/@types/filesystem/-/filesystem-0.0.32.tgz",
+ "integrity": "sha512-Yuf4jR5YYMR2DVgwuCiP11s0xuVRyPKmz8vo6HBY3CGdeMj8af93CFZX+T82+VD1+UqHOxTq31lO7MI7lepBtQ==",
+ "dev": true,
+ "dependencies": {
+ "@types/filewriter": "*"
}
},
+ "node_modules/@types/filewriter": {
+ "version": "0.0.29",
+ "resolved": "https://registry.npmjs.org/@types/filewriter/-/filewriter-0.0.29.tgz",
+ "integrity": "sha512-BsPXH/irW0ht0Ji6iw/jJaK8Lj3FJemon2gvEqHKpCdDCeemHa+rI3WBGq5z7cDMZgoLjY40oninGxqk+8NzNQ==",
+ "dev": true
+ },
+ "node_modules/@types/node": {
+ "version": "18.7.14",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.14.tgz",
+ "integrity": "sha512-6bbDaETVi8oyIARulOE9qF1/Qdi/23z6emrUh0fNJRUmjznqrixD4MpGDdgOFk5Xb0m2H6Xu42JGdvAxaJR/wA==",
+ "dev": true
+ },
"node_modules/mime": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz",
@@ -18,13 +44,51 @@
"engines": {
"node": ">=4.0.0"
}
+ },
+ "node_modules/typescript": {
+ "version": "4.8.2",
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.2.tgz",
+ "integrity": "sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw==",
+ "bin": {
+ "tsc": "bin/tsc",
+ "tsserver": "bin/tsserver"
+ },
+ "engines": {
+ "node": ">=4.2.0"
+ }
}
},
"dependencies": {
+ "@types/filesystem": {
+ "version": "0.0.32",
+ "resolved": "https://registry.npmjs.org/@types/filesystem/-/filesystem-0.0.32.tgz",
+ "integrity": "sha512-Yuf4jR5YYMR2DVgwuCiP11s0xuVRyPKmz8vo6HBY3CGdeMj8af93CFZX+T82+VD1+UqHOxTq31lO7MI7lepBtQ==",
+ "dev": true,
+ "requires": {
+ "@types/filewriter": "*"
+ }
+ },
+ "@types/filewriter": {
+ "version": "0.0.29",
+ "resolved": "https://registry.npmjs.org/@types/filewriter/-/filewriter-0.0.29.tgz",
+ "integrity": "sha512-BsPXH/irW0ht0Ji6iw/jJaK8Lj3FJemon2gvEqHKpCdDCeemHa+rI3WBGq5z7cDMZgoLjY40oninGxqk+8NzNQ==",
+ "dev": true
+ },
+ "@types/node": {
+ "version": "18.7.14",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.14.tgz",
+ "integrity": "sha512-6bbDaETVi8oyIARulOE9qF1/Qdi/23z6emrUh0fNJRUmjznqrixD4MpGDdgOFk5Xb0m2H6Xu42JGdvAxaJR/wA==",
+ "dev": true
+ },
"mime": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz",
"integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg=="
+ },
+ "typescript": {
+ "version": "4.8.2",
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.2.tgz",
+ "integrity": "sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw=="
}
}
}
diff --git a/package.json b/package.json
index 988f135..e439954 100644
--- a/package.json
+++ b/package.json
@@ -4,9 +4,14 @@
"description": "",
"author": "",
"scripts": {
- "start": "node server.improved.js"
+ "start": "node server.improved.ts"
},
"dependencies": {
"mime": "^2.4.4"
+ },
+ "devDependencies": {
+ "@types/filesystem": "^0.0.32",
+ "@types/node": "^18.7.14",
+ "typescript": "^4.8.2"
}
}
diff --git a/public/index.html b/public/index.html
index c56d620..a488146 100644
--- a/public/index.html
+++ b/public/index.html
@@ -1,41 +1,41 @@
-
- CS4241 Assignment 2
-
-
-
-
-
-
+
diff --git a/public/js/scripts.js b/public/js/scripts.js
index de052ea..7282d9f 100644
--- a/public/js/scripts.js
+++ b/public/js/scripts.js
@@ -1,3 +1,2 @@
// Add some Javascript code here, to run on the front end.
-
-console.log("Welcome to assignment 2!")
\ No newline at end of file
+console.log("Welcome to assignment 2!");
diff --git a/public/js/scripts.ts b/public/js/scripts.ts
new file mode 100644
index 0000000..de052ea
--- /dev/null
+++ b/public/js/scripts.ts
@@ -0,0 +1,3 @@
+// Add some Javascript code here, to run on the front end.
+
+console.log("Welcome to assignment 2!")
\ No newline at end of file
diff --git a/server.improved.js b/server.improved.js
index 26673fc..25609e3 100644
--- a/server.improved.js
+++ b/server.improved.js
@@ -1,72 +1,55 @@
-const http = require( 'http' ),
- fs = require( 'fs' ),
- // IMPORTANT: you must run `npm install` in the directory for this assignment
- // to install the mime library used in the following line of code
- mime = require( 'mime' ),
- dir = 'public/',
- port = 3000
-
-const appdata = [
- { 'model': 'toyota', 'year': 1999, 'mpg': 23 },
- { 'model': 'honda', 'year': 2004, 'mpg': 30 },
- { 'model': 'ford', 'year': 1987, 'mpg': 14}
-]
-
-const server = http.createServer( function( request,response ) {
- if( request.method === 'GET' ) {
- handleGet( request, response )
- }else if( request.method === 'POST' ){
- handlePost( request, response )
- }
-})
-
-const handleGet = function( request, response ) {
- const filename = dir + request.url.slice( 1 )
-
- if( request.url === '/' ) {
- sendFile( response, 'public/index.html' )
- }else{
- sendFile( response, filename )
- }
-}
-
-const handlePost = function( request, response ) {
- let dataString = ''
-
- request.on( 'data', function( data ) {
- dataString += data
- })
-
- request.on( 'end', function() {
- console.log( JSON.parse( dataString ) )
-
- // ... do something with the data here!!!
-
- response.writeHead( 200, "OK", {'Content-Type': 'text/plain' })
- response.end()
- })
-}
-
-const sendFile = function( response, filename ) {
- const type = mime.getType( filename )
-
- fs.readFile( filename, function( err, content ) {
-
- // if the error = null, then we've loaded the file successfully
- if( err === null ) {
-
- // status code: https://httpstatuses.com
- response.writeHeader( 200, { 'Content-Type': type })
- response.end( content )
-
- }else{
-
- // file not found, error code 404
- response.writeHeader( 404 )
- response.end( '404 Error: File Not Found' )
-
- }
- })
-}
-
-server.listen( process.env.PORT || port )
+var http = require('http'), fs = require('fs'),
+// IMPORTANT: you must run `npm install` in the directory for this assignment
+// to install the mime library used in the following line of code
+mime = require('mime'), dir = 'public/', port = 3000;
+var appdata = [
+ { 'model': 'toyota', 'year': 1999, 'mpg': 23 },
+ { 'model': 'honda', 'year': 2004, 'mpg': 30 },
+ { 'model': 'ford', 'year': 1987, 'mpg': 14 }
+];
+var server = http.createServer(function (request, response) {
+ if (request.method === 'GET') {
+ handleGet(request, response);
+ }
+ else if (request.method === 'POST') {
+ handlePost(request, response);
+ }
+});
+var handleGet = function (request, response) {
+ var filename = dir + request.url.slice(1);
+ if (request.url === '/') {
+ sendFile(response, 'public/index.html');
+ }
+ else {
+ sendFile(response, filename);
+ }
+};
+var handlePost = function (request, response) {
+ var dataString = '';
+ request.on('data', function (data) {
+ dataString += data;
+ });
+ request.on('end', function () {
+ console.log(JSON.parse(dataString));
+ // ... do something with the data here!!!
+ response.writeHead(200, "OK", { 'Content-Type': 'text/plain' });
+ response.end();
+ });
+};
+var sendFile = function (response, filename) {
+ var type = mime.getType(filename);
+ fs.readFile(filename, function (err, content) {
+ // if the error = null, then we've loaded the file successfully
+ if (err === null) {
+ // status code: https://httpstatuses.com
+ response.writeHeader(200, { 'Content-Type': type });
+ response.end(content);
+ }
+ else {
+ // file not found, error code 404
+ response.writeHeader(404);
+ response.end('404 Error: File Not Found');
+ }
+ });
+};
+server.listen(process.env.PORT || port);
diff --git a/server.improved.ts b/server.improved.ts
new file mode 100644
index 0000000..1830bdc
--- /dev/null
+++ b/server.improved.ts
@@ -0,0 +1,67 @@
+const http = require( 'http' ),
+ fs = require( 'fs' ),
+ // IMPORTANT: you must run `npm install` in the directory for this assignment
+ // to install the mime library used in the following line of code
+ mime = require( 'mime' ),
+ dir = 'public/',
+ port = 3000;
+
+const appdata = [
+ { 'model': 'toyota', 'year': 1999, 'mpg': 23 },
+ { 'model': 'honda', 'year': 2004, 'mpg': 30 },
+ { 'model': 'ford', 'year': 1987, 'mpg': 14}
+];
+
+const server = http.createServer( function( request,response ) {
+ if( request.method === 'GET' ) {
+ handleGet( request, response );
+ } else if( request.method === 'POST' ){
+ handlePost(request, response);
+ }
+});
+
+const handleGet = function( request, response ) {
+ const filename = dir + request.url.slice( 1 );
+
+ if( request.url === '/' ) {
+ sendFile( response, 'public/index.html' );
+ }else{
+ sendFile( response, filename );
+ }
+}
+
+const handlePost = function( request, response ) {
+ let dataString = '';
+
+ request.on( 'data', function( data ) {
+ dataString += data;
+ });
+
+ request.on( 'end', function() {
+ console.log( JSON.parse( dataString ) );
+
+ // ... do something with the data here!!!
+
+ response.writeHead( 200, "OK", {'Content-Type': 'text/plain' })
+ response.end()
+ });
+}
+
+const sendFile = function( response, filename ) {
+ const type = mime.getType( filename )
+
+ fs.readFile( filename, function( err, content ) {
+ // if the error = null, then we've loaded the file successfully
+ if( err === null ) {
+ // status code: https://httpstatuses.com
+ response.writeHeader( 200, { 'Content-Type': type });
+ response.end( content );
+ }else{
+ // file not found, error code 404
+ response.writeHeader( 404 );
+ response.end( '404 Error: File Not Found' );
+ }
+ })
+}
+
+server.listen( process.env.PORT || port )
From cb13847808981e1d14eaf267725d51370a0c4963 Mon Sep 17 00:00:00 2001
From: chjm6
Date: Wed, 7 Sep 2022 20:46:23 -0400
Subject: [PATCH 03/12] Set up Typescript
---
package.json | 2 +-
public/js/scripts.js | 1 +
server.improved.js | 26 ++++++-----
server.improved.ts | 26 +++++++----
tsconfig.json | 103 +++++++++++++++++++++++++++++++++++++++++++
5 files changed, 137 insertions(+), 21 deletions(-)
create mode 100644 tsconfig.json
diff --git a/package.json b/package.json
index e439954..9adaba8 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,7 @@
"description": "",
"author": "",
"scripts": {
- "start": "node server.improved.ts"
+ "start": "node server.improved.js"
},
"dependencies": {
"mime": "^2.4.4"
diff --git a/public/js/scripts.js b/public/js/scripts.js
index 7282d9f..35e7a9c 100644
--- a/public/js/scripts.js
+++ b/public/js/scripts.js
@@ -1,2 +1,3 @@
+"use strict";
// Add some Javascript code here, to run on the front end.
console.log("Welcome to assignment 2!");
diff --git a/server.improved.js b/server.improved.js
index 25609e3..1ea669c 100644
--- a/server.improved.js
+++ b/server.improved.js
@@ -1,13 +1,15 @@
-var http = require('http'), fs = require('fs'),
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+const http = require('http'), fs = require('fs'),
// IMPORTANT: you must run `npm install` in the directory for this assignment
// to install the mime library used in the following line of code
mime = require('mime'), dir = 'public/', port = 3000;
-var appdata = [
+const appdata = [
{ 'model': 'toyota', 'year': 1999, 'mpg': 23 },
{ 'model': 'honda', 'year': 2004, 'mpg': 30 },
{ 'model': 'ford', 'year': 1987, 'mpg': 14 }
];
-var server = http.createServer(function (request, response) {
+const server = http.createServer(function (request, response) {
if (request.method === 'GET') {
handleGet(request, response);
}
@@ -15,8 +17,10 @@ var server = http.createServer(function (request, response) {
handlePost(request, response);
}
});
-var handleGet = function (request, response) {
- var filename = dir + request.url.slice(1);
+const handleGet = function (request, response) {
+ if (request === undefined)
+ throw new TypeError("request cannot be undefined");
+ const filename = dir + request.url?.slice(1);
if (request.url === '/') {
sendFile(response, 'public/index.html');
}
@@ -24,8 +28,8 @@ var handleGet = function (request, response) {
sendFile(response, filename);
}
};
-var handlePost = function (request, response) {
- var dataString = '';
+const handlePost = function (request, response) {
+ let dataString = '';
request.on('data', function (data) {
dataString += data;
});
@@ -36,18 +40,18 @@ var handlePost = function (request, response) {
response.end();
});
};
-var sendFile = function (response, filename) {
- var type = mime.getType(filename);
+const sendFile = function (response, filename) {
+ const type = mime.getType(filename);
fs.readFile(filename, function (err, content) {
// if the error = null, then we've loaded the file successfully
if (err === null) {
// status code: https://httpstatuses.com
- response.writeHeader(200, { 'Content-Type': type });
+ response.writeHead(200, { 'Content-Type': type });
response.end(content);
}
else {
// file not found, error code 404
- response.writeHeader(404);
+ response.writeHead(404);
response.end('404 Error: File Not Found');
}
});
diff --git a/server.improved.ts b/server.improved.ts
index 1830bdc..35bad38 100644
--- a/server.improved.ts
+++ b/server.improved.ts
@@ -1,3 +1,8 @@
+import {IncomingMessage, ServerResponse} from "http";
+import {constants} from "os";
+import ErrnoException = NodeJS.ErrnoException;
+import {Serializer} from "v8";
+
const http = require( 'http' ),
fs = require( 'fs' ),
// IMPORTANT: you must run `npm install` in the directory for this assignment
@@ -12,7 +17,7 @@ const appdata = [
{ 'model': 'ford', 'year': 1987, 'mpg': 14}
];
-const server = http.createServer( function( request,response ) {
+const server = http.createServer( function( request: IncomingMessage, response: ServerResponse ) {
if( request.method === 'GET' ) {
handleGet( request, response );
} else if( request.method === 'POST' ){
@@ -20,8 +25,11 @@ const server = http.createServer( function( request,response ) {
}
});
-const handleGet = function( request, response ) {
- const filename = dir + request.url.slice( 1 );
+const handleGet = function( request: IncomingMessage, response: ServerResponse ) {
+ if (request === undefined)
+ throw new TypeError("request cannot be undefined");
+
+ const filename = dir + request.url?.slice( 1 );
if( request.url === '/' ) {
sendFile( response, 'public/index.html' );
@@ -30,7 +38,7 @@ const handleGet = function( request, response ) {
}
}
-const handlePost = function( request, response ) {
+const handlePost = function( request: IncomingMessage, response: ServerResponse ) {
let dataString = '';
request.on( 'data', function( data ) {
@@ -47,18 +55,18 @@ const handlePost = function( request, response ) {
});
}
-const sendFile = function( response, filename ) {
+const sendFile = function( response: ServerResponse, filename: string ) {
const type = mime.getType( filename )
- fs.readFile( filename, function( err, content ) {
+ fs.readFile( filename, function( err: ErrnoException, content: Buffer ) {
// if the error = null, then we've loaded the file successfully
if( err === null ) {
// status code: https://httpstatuses.com
- response.writeHeader( 200, { 'Content-Type': type });
+ response.writeHead( 200, { 'Content-Type': type });
response.end( content );
- }else{
+ } else {
// file not found, error code 404
- response.writeHeader( 404 );
+ response.writeHead( 404 );
response.end( '404 Error: File Not Found' );
}
})
diff --git a/tsconfig.json b/tsconfig.json
new file mode 100644
index 0000000..57ed895
--- /dev/null
+++ b/tsconfig.json
@@ -0,0 +1,103 @@
+{
+ "compilerOptions": {
+ /* Visit https://aka.ms/tsconfig to read more about this file */
+
+ /* Projects */
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
+
+ /* Language and Environment */
+ "target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
+ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
+
+ /* Modules */
+ "module": "commonjs", /* Specify what module code is generated. */
+ // "rootDir": "./", /* Specify the root folder within your source files. */
+ "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
+ // "resolveJsonModule": true, /* Enable importing .json files. */
+ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */
+
+ /* JavaScript Support */
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
+
+ /* Emit */
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
+ // "outDir": "./", /* Specify an output folder for all emitted files. */
+ // "removeComments": true, /* Disable emitting comments. */
+ // "noEmit": true, /* Disable emitting files from a compilation. */
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
+
+ /* Interop Constraints */
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
+
+ /* Type Checking */
+ "strict": true, /* Enable all strict type-checking options. */
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
+
+ /* Completeness */
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
+ }
+}
From 484a7d39a5379aac1fa76ed9ea9eec9835476646 Mon Sep 17 00:00:00 2001
From: chjm6
Date: Wed, 7 Sep 2022 21:53:18 -0400
Subject: [PATCH 04/12] Basic server response
---
public/index.html | 16 +++++++---------
server.improved.js | 7 +++++--
server.improved.ts | 9 ++++++---
3 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/public/index.html b/public/index.html
index a488146..e11a749 100644
--- a/public/index.html
+++ b/public/index.html
@@ -14,27 +14,25 @@
const submit = function (e) {
// prevent default form action from being carried out
- e.preventDefault()
+ e.preventDefault();
const input = document.querySelector('#yourname'),
json = {yourname: input.value},
- body = JSON.stringify(json)
+ body = JSON.stringify(json);
fetch('/submit', {
method: 'POST',
body
})
- .then(function (response) {
- // do something with the reponse
- console.log(response)
- })
+ .then((response) => response.json())
+ .then((json) => console.log(json));
- return false
+ return false;
}
window.onload = function () {
- const button = document.querySelector('button')
- button.onclick = submit
+ const button = document.querySelector('button');
+ button.onclick = submit;
}
diff --git a/server.improved.js b/server.improved.js
index 1ea669c..355f5ef 100644
--- a/server.improved.js
+++ b/server.improved.js
@@ -34,10 +34,13 @@ const handlePost = function (request, response) {
dataString += data;
});
request.on('end', function () {
- console.log(JSON.parse(dataString));
+ let data = { yourname: "" };
+ data = JSON.parse(dataString);
+ console.log(data);
// ... do something with the data here!!!
+ // response.write(dataString);
response.writeHead(200, "OK", { 'Content-Type': 'text/plain' });
- response.end();
+ response.end(dataString);
});
};
const sendFile = function (response, filename) {
diff --git a/server.improved.ts b/server.improved.ts
index 35bad38..3292d39 100644
--- a/server.improved.ts
+++ b/server.improved.ts
@@ -46,12 +46,15 @@ const handlePost = function( request: IncomingMessage, response: ServerResponse
});
request.on( 'end', function() {
- console.log( JSON.parse( dataString ) );
+ let data = {yourname: ""}
+ data = JSON.parse(dataString);
+ console.log(data);
// ... do something with the data here!!!
+ // response.write(dataString);
- response.writeHead( 200, "OK", {'Content-Type': 'text/plain' })
- response.end()
+ response.writeHead( 200, "OK", {'Content-Type': 'text/plain' });
+ response.end(dataString);
});
}
From b6b1bdb42bfc6d02d7f82d915014c9cd5241dc7d Mon Sep 17 00:00:00 2001
From: chjm6
Date: Thu, 8 Sep 2022 01:41:08 -0400
Subject: [PATCH 05/12] Stuck on GET request
---
package.json | 2 +-
public/css/style.css | 1 -
public/css/styles.css | 95 +++++++++++++++++++
public/index.html | 54 +++++------
public/js/scripts.js | 34 ++++++-
public/js/scripts.ts | 50 +++++++++-
.../server.improved.js | 19 ++--
.../server.improved.ts | 29 ++++--
8 files changed, 233 insertions(+), 51 deletions(-)
delete mode 100644 public/css/style.css
create mode 100644 public/css/styles.css
rename server.improved.js => server/server.improved.js (78%)
rename server.improved.ts => server/server.improved.ts (76%)
diff --git a/package.json b/package.json
index 9adaba8..6629e79 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,7 @@
"description": "",
"author": "",
"scripts": {
- "start": "node server.improved.js"
+ "start": "node server/server.improved.js"
},
"dependencies": {
"mime": "^2.4.4"
diff --git a/public/css/style.css b/public/css/style.css
deleted file mode 100644
index d5f842a..0000000
--- a/public/css/style.css
+++ /dev/null
@@ -1 +0,0 @@
-/*Style your own assignment! This is fun! */
\ No newline at end of file
diff --git a/public/css/styles.css b/public/css/styles.css
new file mode 100644
index 0000000..43c8908
--- /dev/null
+++ b/public/css/styles.css
@@ -0,0 +1,95 @@
+/*fonts*/
+@import
+url('https://fonts.googleapis.com/css2?family=Roboto&display=swap');
+
+* {
+ font-family: 'Roboto', sans-serif;
+}
+
+/*Global fonts*/
+h1 {
+ font-size: 60pt;
+}
+
+h1, h2, h3 {
+ font-weight: 100;
+}
+
+/*Body*/
+body {
+ margin: 0;
+ background-color: #ABCADE;
+}
+
+/*Animate a fade-in entry for every site element*/
+:not(body, div, section, html) {
+ animation: loadin 1s ease forwards;
+}
+
+@keyframes loadin {
+ from {
+ opacity: 0;
+ transform: translateY(10pt);
+ }
+ to {
+ opacity: 1;
+ transform: translateY(0pt);
+ }
+}
+
+/*Section Styling*/
+section {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+}
+
+section:nth-child(odd) {
+ background-color: #A0BED1;
+ padding: 20pt 0pt 20pt 0pt;
+}
+
+section:nth-child(even) {
+ background-color: #ABCADE;
+ padding: 20pt 0pt 20pt 0pt;
+}
+
+/*Organizational*/
+.content {
+ width: clamp(400px, 67%, 1280px);
+}
+
+.hbox {
+ display: flex;
+ flex-direction: row;
+}
+
+.vbox {
+ display: flex;
+ flex-direction: column;
+}
+
+.flex-center {
+ display: flex;
+ align-content: center;
+ justify-items: center;
+}
+
+hr {
+ margin: 40pt auto;
+}
+
+/*Form styles*/
+#new-note-form > * {
+ margin: 0 5px;
+}
+
+#message {
+ flex-grow: 1;
+}
+
+#submit {
+ width: auto;
+ padding: 2px 20px;
+ margin-left: 10%;
+}
diff --git a/public/index.html b/public/index.html
index e11a749..17891ff 100644
--- a/public/index.html
+++ b/public/index.html
@@ -3,37 +3,31 @@
CS4241 Assignment 2
+
+
-
-
-
+
+
+
+