-
Notifications
You must be signed in to change notification settings - Fork 19
Michael Tse http with persistence #15
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
MTse3
wants to merge
7
commits into
codefellows-sea-d45-javascript:master
Choose a base branch
from
MTse3: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
7 commits
Select commit
Hold shift + click to select a range
d26f419
able to return json file in file to webpage
MTse3 03e0ccc
post request works and can get json file to display on page
MTse3 0520c22
added tests
MTse3 cb87715
Merge pull request #1 from MTse3/test
MTse3 08d198c
changed git ignore
MTse3 5eeb354
Merge pull request #2 from MTse3/gitignore
MTse3 916ba41
gitignore fixed
MTse3 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 was deleted.
Oops, something went wrong.
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,2 @@ | ||
| node_modules | ||
| data |
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
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,33 @@ | ||
| var gulp = require('gulp'); | ||
| var jshint = require('gulp-jshint'); | ||
| var mocha = require('gulp-mocha'); | ||
| var appFiles = ['server.js']; | ||
| var testFiles = ['./test/**/*.js']; | ||
|
|
||
| gulp.task('jshint:test', function(){ | ||
| return gulp.src(testFiles) | ||
| .pipe(jshint({ | ||
| node:true, | ||
| globals: { | ||
| describe: true, | ||
| it: true, | ||
| before: true, | ||
| beforeEach: true, | ||
| after: true | ||
| } | ||
| })) | ||
| .pipe(jshint.reporter('default')); | ||
| }); | ||
|
|
||
| gulp.task('jshint:app', function(){ | ||
| return gulp.src(appFiles) | ||
| .pipe(jshint.reporter('default')); | ||
| }); | ||
|
|
||
| gulp.task('mocha', ['jshint'], function(){ | ||
| return gulp.src('./test/test.js', {read:false}) | ||
| .pipe(mocha({reporter:'spec'})); | ||
| }); | ||
|
|
||
| gulp.task('jshint', ['jshint:test', 'jshint:app']); | ||
| gulp.task('default', ['jshint', 'mocha']); |
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,21 @@ | ||
| { | ||
| "name": "http_with_persistence", | ||
| "version": "0.1.0", | ||
| "description": "", | ||
| "main": "server.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "start": "node server.js" | ||
| }, | ||
| "author": "", | ||
| "license": "MIT", | ||
| "devDependencies": { | ||
| "chai": "^3.4.1", | ||
| "chai-http": "^1.0.0", | ||
| "gulp-jshint": "^1.12.0", | ||
| "gulp-mocha": "^2.1.3" | ||
| }, | ||
| "dependencies": { | ||
| "express": "^4.13.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,39 @@ | ||
| var express = require('express'); | ||
| var app = express(); | ||
| var http = require('http'); | ||
| var fs = require('fs'); | ||
|
|
||
| //converts incomming requests into string for future use | ||
| var processData = function(req, res, next) { | ||
| console.log('process data'); | ||
| var data = ''; | ||
| req.on('data', function(reqData) { | ||
| data = data + reqData.toString(); | ||
| }); | ||
| req.on('end', function(endData) { | ||
| req.body = data; | ||
| next(); | ||
| }); | ||
| }; | ||
|
|
||
| app.use(processData); | ||
|
|
||
| //takes in a post request and stores newly made json file in data directory. | ||
| app.post('/:name', function(req, res) { | ||
| fs.writeFileSync(__dirname + '/data/' + req.params.name + '.json', req.body); | ||
| res.send(req.body); | ||
| //console log confirms to server file was posted | ||
| console.log('posted new file: ' + req.params.name + '.json'); | ||
| }); | ||
|
|
||
| // A get request to the same route should return the data contained in the json file. | ||
| app.get('/:name', function(req, res) { | ||
| fs.readFile(__dirname + '/data/' + req.params.name + '.json', function(err, data) { | ||
| if(err) throw err; | ||
| res.send(data.toString()); | ||
| }); | ||
| }); | ||
|
|
||
| app.listen(3000, function() { | ||
| console.log('server up!!'); | ||
| }); | ||
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,31 @@ | ||
| var chai = require('chai'); | ||
| var chaihttp = require('chai-http'); | ||
| chai.use(chaihttp); | ||
| var expect = chai.expect; | ||
| var fs = require('fs'); | ||
| require(__dirname + '/../server'); | ||
|
|
||
| describe('The server file', function() { | ||
| it('should respond to a post request', function(done) { | ||
| chai.request('localhost:3000') | ||
| .post('/note_one') | ||
| .send('{noteBody: \'hello world\'}') | ||
| .end(function(err, res) { | ||
| expect(err).to.eql(null); | ||
| expect(res).to.have.status(200); | ||
| expect(res.text).to.eql('{noteBody: \'hello world\'}'); | ||
| done(); | ||
| }); | ||
| }); | ||
| it('should be able to recieve and send json file to screen', function(done) { | ||
| chai.request('localhost:3000') | ||
| //assumes there is a sample.json file in the data directory with {"msg": "hello Felix"} | ||
| .get('/sample') | ||
| .end(function(err, res) { | ||
| expect(err).to.eql(null); | ||
| expect(res).to.have.status(200); | ||
| expect(res.text).to.eql('{"msg": \"hello Felix\"}\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.
is this necessary for this assignment?