diff --git a/README.md b/README.md index 3945c152..65aa31a5 100755 --- a/README.md +++ b/README.md @@ -1,93 +1,9 @@ -Assignment 2 - Short Stack: Basic Two-tier Web Application using HTML/CSS/JS and Node.js -=== - -Due: September 16th, by 11:59 PM. - -This assignment aims to introduce you to the concepts and practice involved in creating a prototype (i.e. not deployment ready) two-tiered web application. The baseline aims of this assignment involve creating an application that demonstrates the use of several specific pieces of HTML, CSS, JavaScript, and Node.js functionality. - -Baseline Requirements ---- - -Note that there is a very large range of application areas and possibilities that meet these baseline requirements. Make your application do something useful! A todo list, storing / retrieving high scores for a very simple game, have a little fun with it. - -Your application is required to implement the following functionalities: - -- a `Server` which not only serves files, but also maintains a tabular dataset with 3 or more fields related to your application -- a `Results` functionality which shows the entire dataset residing in the server's memory -- a `Form/Entry` functionality which allows a user to add, modify, or delete data items residing in the server's memory -- a `Server Logic` which, upon receiving new or modified "incoming" data, includes and uses a function that adds at least one additional derived field to this incoming data before integrating it with the existing dataset -- the `Derived field` for a new row of data must be computed based on fields already existing in the row. For example, a `todo` dataset with `task`, `priority`, and `creation_date` may generate a new field `deadline` by looking at `creation_date` and `priority` - -Your application is required to demonstrate the use of the following concepts: - -HTML: -- One or more [HTML Forms](https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms), with any combination of form tags appropriate for the user input portion of the application -- A results page displaying all data currently available on the server. You will most likely use a `` tag for this, but `
+ + + + + + + + + + + + + diff --git a/server.improved.js b/server.improved.js index 26673fc0..9493cf90 100644 --- a/server.improved.js +++ b/server.improved.js @@ -6,11 +6,7 @@ const http = require( 'http' ), 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 dataStorage = [] const server = http.createServer( function( request,response ) { if( request.method === 'GET' ) { @@ -29,21 +25,26 @@ const handleGet = function( request, response ) { sendFile( response, filename ) } } - +//let dataStorage= [] const handlePost = function( request, response ) { - let dataString = '' + request.on( 'data', function( data ) { - dataString += data + const dataStuff = JSON.parse(data) + var canDrink = parseInt(dataStuff.age) >= 21 + if(canDrink){ + dataStuff.isLegal = "Yes" + } + else{ + dataStuff.isLegal = "No" + } + dataStorage.push ( dataStuff ) }) 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() + response.end( JSON.stringify( dataStorage )) }) } diff --git a/shrinkwrap.yaml b/shrinkwrap.yaml new file mode 100644 index 00000000..f6d7ea4f --- /dev/null +++ b/shrinkwrap.yaml @@ -0,0 +1,15 @@ +dependencies: + mime: 2.4.6 +packages: + /mime/2.4.6: + dev: false + engines: + node: '>=4.0.0' + hasBin: true + resolution: + integrity: sha512-RZKhC3EmpBchfTGBVb8fb+RL2cWyw/32lshnsETttkBAyAUXSGHxbEJWWRXc751DrIxG1q04b8QwMbAwkRPpUA== +registry: 'https://registry.npmjs.org/' +shrinkwrapMinorVersion: 9 +shrinkwrapVersion: 3 +specifiers: + mime: ^2.4.4