-
Notifications
You must be signed in to change notification settings - Fork 19
Assignment due Tuesday, November 10, 2015 #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
picklekitch
wants to merge
4
commits into
codefellows-sea-d45-javascript:master
Choose a base branch
from
picklekitch:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| **/*.sw? | ||
| **/node_modules | ||
| **/data |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "name": "http_with_persistence", | ||
| "version": "1.0.0", | ||
| "description": "Describe deeznutz", | ||
| "main": "server.js", | ||
| "directories": { | ||
| "test": "test" | ||
| }, | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/picklekitch/http_with_persistence.git" | ||
| }, | ||
| "author": "Will Kitchell (william.kitchell@gmail.com)", | ||
| "license": "ISC", | ||
| "bugs": { | ||
| "url": "https://github.com/picklekitch/http_with_persistence/issues" | ||
| }, | ||
| "homepage": "https://github.com/picklekitch/http_with_persistence#readme", | ||
| "devDependencies": { | ||
| "body-parser": "^1.14.1", | ||
| "chai": "^3.4.1", | ||
| "chai-http": "^1.0.0", | ||
| "express": "^4.13.3", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Express is a dependency, not a devDependency. |
||
| "mocha": "^2.3.3" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| 'use strict'; | ||
|
|
||
| var fs = require('fs'); | ||
| var express = require('express'); | ||
| var app = express(); | ||
|
|
||
| app.set('port', (process.env.PORT || 5000)); | ||
|
|
||
| var handleData = function(req, res, next) { | ||
| var data = ''; | ||
|
|
||
| req.on('data', function(reqData) { | ||
| data = data + reqData.toString(); | ||
| }); | ||
|
|
||
| req.on('end', function(endData) { | ||
| req.body = data; | ||
| next(); | ||
| }); | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a small project, but ideally your handleData function would be modularized. |
||
|
|
||
| app.get('/data/:id', function(req, res) { | ||
| fs.readFile(__dirname + '/data/' + req.params.id + '.json', function(err, data) { | ||
| res.send(data.toString()); | ||
| }); | ||
| }); | ||
|
|
||
| app.post('/data/:id', handleData, function(req, res) { | ||
| fs.appendFile(__dirname + '/data/' + req.params.id + '.json', req.body, function(err) { | ||
| if (err) throw err; | ||
|
|
||
| res.send('file created'); | ||
| }); | ||
| }); | ||
|
|
||
| app.listen(app.get('port'), function() { | ||
| console.log('Server listening at ' + app.get('port') + '.'); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| var fs = require('fs'); | ||
| var chai = require('chai'); | ||
| var expect = chai.exepct; | ||
| var chaiHttp = require('chai-http'); | ||
| var express = require('express'); | ||
| chai.use(chaiHttp); | ||
|
|
||
| var server = require(__dirname + '/../server.js'); | ||
|
|
||
| describe('The server.js file', function (){ | ||
| it('should write a json file in the /data folder', function(done){ | ||
| expect(fs.readFileSync('./data/data.json')); | ||
| }); | ||
| }); | ||
|
|
||
| describe('post req', function() { | ||
| it('should respond to file creation', function(done) { | ||
| chai.request('http://localhost:5000') | ||
| .post('/data/test') | ||
| .send({'hello':'world'}) | ||
| .end(function(err, res) { | ||
| expect(res.text).to.eql('file created'); | ||
| done(); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('get req', function() { | ||
| it('should read test file', function(done) { | ||
| chai.request('http://localhost:5000') | ||
| .get('/data/testfile') | ||
| .end(function(err, res) { | ||
| expect(err).to.equal(null); | ||
| expect(res).to.have.status(200); | ||
| expect(res.text).to.eql('{"hello":"world"}\n'); | ||
| done(); | ||
| }); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Body-parser should be a dependency, but you didn't use it, so it should be removed from this list.