From fe8c4d506435cfdb483c8290dd4f02ec69006f2d Mon Sep 17 00:00:00 2001 From: Isabella Organ Date: Tue, 10 Nov 2015 05:16:28 -0800 Subject: [PATCH 1/6] initial file structure setup --- isabella_organ/.gitignore | 2 ++ isabella_organ/README.md | 27 +++++++++++++++++++++++++++ isabella_organ/gulpfile.js | 0 isabella_organ/index.js | 0 isabella_organ/lib/server.js | 0 isabella_organ/package.json | 25 +++++++++++++++++++++++++ isabella_organ/test/test.js | 0 7 files changed, 54 insertions(+) create mode 100644 isabella_organ/.gitignore create mode 100644 isabella_organ/README.md create mode 100644 isabella_organ/gulpfile.js create mode 100644 isabella_organ/index.js create mode 100644 isabella_organ/lib/server.js create mode 100644 isabella_organ/package.json create mode 100644 isabella_organ/test/test.js diff --git a/isabella_organ/.gitignore b/isabella_organ/.gitignore new file mode 100644 index 0000000..7ddf381 --- /dev/null +++ b/isabella_organ/.gitignore @@ -0,0 +1,2 @@ +**/*.sw? +**/node_modules diff --git a/isabella_organ/README.md b/isabella_organ/README.md new file mode 100644 index 0000000..a35695b --- /dev/null +++ b/isabella_organ/README.md @@ -0,0 +1,27 @@ +HTTP Server With Persistence +============================ +To complete this assignment: + * fork this repository (the sub module for this specific assignment) + * clone down your fork + * place all of your work in a folder that is your full name, use `_`s instead of spaces + * push back up to your fork + * create a pull request back to the original repo + * submit a link to the PR in canvas + +Assignment Description +-------------------------- +For this assignment, write an http server that will act as a simple data store. + +It should respond to GET/POST requests for a single route and +the data coming in from a post request should be saved to a json file in +a data folder in your repository. DO NOT commit your data folder to git. For example + if a request is sent to "/note_one" with a body of {noteBody: 'hello world'} +the json data in the body should be stored in it's own json file `data/note_one.json`. +A get request to the same route should return the data contained in the json file. + +Rubric: + + * Handles REST requests: 3pts + * JSON storage: 3pts + * Tests: 2pts + * Project Organization and Development Files: 2pts diff --git a/isabella_organ/gulpfile.js b/isabella_organ/gulpfile.js new file mode 100644 index 0000000..e69de29 diff --git a/isabella_organ/index.js b/isabella_organ/index.js new file mode 100644 index 0000000..e69de29 diff --git a/isabella_organ/lib/server.js b/isabella_organ/lib/server.js new file mode 100644 index 0000000..e69de29 diff --git a/isabella_organ/package.json b/isabella_organ/package.json new file mode 100644 index 0000000..8d83d5b --- /dev/null +++ b/isabella_organ/package.json @@ -0,0 +1,25 @@ +{ + "name": "isabella_organ", + "version": "1.0.0", + "description": "HTTP server with persistance", + "main": "index.js", + "scripts": { + "test": "./node_modules/mocha/bin/mocha/test" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/isabellaorgan/http_with_persistence.git" + }, + "keywords": [ + "HTTP", + "server", + "express", + "node" + ], + "author": "isabellaorgan@gmail.com", + "license": "MIT", + "bugs": { + "url": "https://github.com/isabellaorgan/http_with_persistence/issues" + }, + "homepage": "https://github.com/isabellaorgan/http_with_persistence#readme" +} diff --git a/isabella_organ/test/test.js b/isabella_organ/test/test.js new file mode 100644 index 0000000..e69de29 From 536581be2ed8dad23e75ee156b8aaf22e60f6a2a Mon Sep 17 00:00:00 2001 From: Isabella Organ Date: Tue, 10 Nov 2015 07:12:03 -0800 Subject: [PATCH 2/6] add dependencies, finish gulpfile, create index content, begin server code --- .gitignore | 2 - README.md | 27 ----------- isabella_organ/.jscsrc | 90 ++++++++++++++++++++++++++++++++++++ isabella_organ/gulpfile.js | 49 ++++++++++++++++++++ isabella_organ/index.js | 3 ++ isabella_organ/lib/server.js | 32 +++++++++++++ isabella_organ/package.json | 10 +++- 7 files changed, 183 insertions(+), 30 deletions(-) delete mode 100644 .gitignore delete mode 100644 README.md create mode 100644 isabella_organ/.jscsrc diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 7ddf381..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -**/*.sw? -**/node_modules diff --git a/README.md b/README.md deleted file mode 100644 index a35695b..0000000 --- a/README.md +++ /dev/null @@ -1,27 +0,0 @@ -HTTP Server With Persistence -============================ -To complete this assignment: - * fork this repository (the sub module for this specific assignment) - * clone down your fork - * place all of your work in a folder that is your full name, use `_`s instead of spaces - * push back up to your fork - * create a pull request back to the original repo - * submit a link to the PR in canvas - -Assignment Description --------------------------- -For this assignment, write an http server that will act as a simple data store. - -It should respond to GET/POST requests for a single route and -the data coming in from a post request should be saved to a json file in -a data folder in your repository. DO NOT commit your data folder to git. For example - if a request is sent to "/note_one" with a body of {noteBody: 'hello world'} -the json data in the body should be stored in it's own json file `data/note_one.json`. -A get request to the same route should return the data contained in the json file. - -Rubric: - - * Handles REST requests: 3pts - * JSON storage: 3pts - * Tests: 2pts - * Project Organization and Development Files: 2pts diff --git a/isabella_organ/.jscsrc b/isabella_organ/.jscsrc new file mode 100644 index 0000000..46ccf87 --- /dev/null +++ b/isabella_organ/.jscsrc @@ -0,0 +1,90 @@ +{ + "requireCurlyBraces": [ + "if", + "else", + "for", + "while", + "do", + "try", + "catch" + ], + "requireOperatorBeforeLineBreak": true, + "requireCamelCaseOrUpperCaseIdentifiers": true, + "maximumLineLength": { + "value": 80, + "allExcept": ["comments", "regex"] + }, + "validateIndentation": 2, + "validateQuoteMarks": "'", + + "disallowMultipleLineStrings": true, + "disallowMixedSpacesAndTabs": true, + "disallowTrailingWhitespace": true, + "disallowSpaceAfterPrefixUnaryOperators": true, + "disallowMultipleVarDecl": true, + "disallowKeywordsOnNewLine": ["else"], + + "requireSpaceAfterKeywords": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "return", + "try", + "catch" + ], + "requireSpaceBeforeBinaryOperators": [ + "=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=", + "&=", "|=", "^=", "+=", + + "+", "-", "*", "/", "%", "<<", ">>", ">>>", "&", + "|", "^", "&&", "||", "===", "==", ">=", + "<=", "<", ">", "!=", "!==" + ], + "requireSpaceAfterBinaryOperators": true, + "requireSpacesInConditionalExpression": true, + "requireSpaceBeforeBlockStatements": true, + "requireSpacesInForStatement": true, + "requireLineFeedAtFileEnd": true, + "requireSpacesInFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "disallowSpacesInAnonymousFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInsideObjectBrackets": "all", + "disallowSpacesInsideArrayBrackets": "all", + "disallowSpacesInsideParentheses": true, + + "disallowMultipleLineBreaks": true, + "disallowNewlineBeforeBlockStatements": true, + "disallowKeywords": ["with"], + "disallowSpacesInFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInFunctionDeclaration": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInCallExpression": true, + "disallowSpaceAfterObjectKeys": true, + "requireSpaceBeforeObjectValues": true, + "requireCapitalizedConstructors": true, + "requireDotNotation": true, + "requireSemicolons": true, + "validateParameterSeparator": ", ", + + "jsDoc": { + "checkAnnotations": "closurecompiler", + "checkParamNames": true, + "requireParamTypes": true, + "checkRedundantParams": true, + "checkReturnTypes": true, + "checkRedundantReturns": true, + "requireReturnTypes": true, + "checkTypes": true, + "checkRedundantAccess": true, + "requireNewlineAfterDescription": true + } +} \ No newline at end of file diff --git a/isabella_organ/gulpfile.js b/isabella_organ/gulpfile.js index e69de29..3a03b16 100644 --- a/isabella_organ/gulpfile.js +++ b/isabella_organ/gulpfile.js @@ -0,0 +1,49 @@ +'use strict' + +var gulp = require('gulp'); +var mocha = require('gulp-mocha'); +var expect = require('chai').expect; +var jshint = require('gulp-jshint'); +var jscs = require('gulp-jscs'); +var stylish = require('gulp-jscs-stylish'); +var appFiles = ['server.js', './lib/**/*.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, + after: true + } + })) + .pipe(jshint.reporter('default')); +}); + +gulp.task('jshint:app', function() { + return gulp.src(appFiles) + .pipe(jshint({ + node: true + })) + .pipe(jshint.reporter('default')); +}); + +gulp.task('jscs', function() { + return gulp.src(appFiles) + .pipe(jscs()) + .pipe(stylish()); +}); + +gulp.task('mocha:test', function () { + return gulp.src(testFiles) + .pipe(mocha({ + // read:false, + reporter: 'spec'})); +}); + +gulp.task('jshint', ['jshint:test', 'jshint:app']); +gulp.task('mocha', ['mocha:test']); +gulp.task('default', ['jscs', 'jshint']); \ No newline at end of file diff --git a/isabella_organ/index.js b/isabella_organ/index.js index e69de29..55408c5 100644 --- a/isabella_organ/index.js +++ b/isabella_organ/index.js @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +require(__dirname + 'lib/server.js'); \ No newline at end of file diff --git a/isabella_organ/lib/server.js b/isabella_organ/lib/server.js index e69de29..4eeda0f 100644 --- a/isabella_organ/lib/server.js +++ b/isabella_organ/lib/server.js @@ -0,0 +1,32 @@ +var express = require('express'); +var app = express(); +var http = require('http'); +var fs = require('fs'); + +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.get('/dataroute', function(req, res) { + console.log('get data route'); + next(); +}); + +app.use(processData); + +app.get('/*', function(req, res) { + res.status(404).json({msg: 'not found'}); +}); + +app.listen(3000, function() { + console.log('server up'); +}); \ No newline at end of file diff --git a/isabella_organ/package.json b/isabella_organ/package.json index 8d83d5b..470082c 100644 --- a/isabella_organ/package.json +++ b/isabella_organ/package.json @@ -21,5 +21,13 @@ "bugs": { "url": "https://github.com/isabellaorgan/http_with_persistence/issues" }, - "homepage": "https://github.com/isabellaorgan/http_with_persistence#readme" + "homepage": "https://github.com/isabellaorgan/http_with_persistence#readme", + "dependencies": { + "express": "^4.13.3" + }, + "devDependencies": { + "chai": "^3.4.1", + "gulp-mocha": "^2.1.3", + "mocha": "^2.3.3" + } } From e9507d2117d7b35214bcf9aa889f4aa3be56eff3 Mon Sep 17 00:00:00 2001 From: Isabella Organ Date: Tue, 10 Nov 2015 20:29:18 -0800 Subject: [PATCH 3/6] update tests, red green refactor, now passing --- isabella_organ/gulpfile.js | 10 +--------- isabella_organ/index.js | 2 +- isabella_organ/lib/server.js | 20 ++++++++++++++------ isabella_organ/package.json | 4 +++- isabella_organ/test/test.js | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/isabella_organ/gulpfile.js b/isabella_organ/gulpfile.js index 3a03b16..0842a21 100644 --- a/isabella_organ/gulpfile.js +++ b/isabella_organ/gulpfile.js @@ -4,8 +4,6 @@ var gulp = require('gulp'); var mocha = require('gulp-mocha'); var expect = require('chai').expect; var jshint = require('gulp-jshint'); -var jscs = require('gulp-jscs'); -var stylish = require('gulp-jscs-stylish'); var appFiles = ['server.js', './lib/**/*.js']; var testFiles = ['./test/**/*.js']; @@ -31,19 +29,13 @@ gulp.task('jshint:app', function() { .pipe(jshint.reporter('default')); }); -gulp.task('jscs', function() { - return gulp.src(appFiles) - .pipe(jscs()) - .pipe(stylish()); -}); gulp.task('mocha:test', function () { return gulp.src(testFiles) .pipe(mocha({ - // read:false, reporter: 'spec'})); }); gulp.task('jshint', ['jshint:test', 'jshint:app']); gulp.task('mocha', ['mocha:test']); -gulp.task('default', ['jscs', 'jshint']); \ No newline at end of file +gulp.task('default', ['jshint']); \ No newline at end of file diff --git a/isabella_organ/index.js b/isabella_organ/index.js index 55408c5..78f6b62 100644 --- a/isabella_organ/index.js +++ b/isabella_organ/index.js @@ -1,3 +1,3 @@ #!/usr/bin/env node -require(__dirname + 'lib/server.js'); \ No newline at end of file +require(__dirname + '/lib/server.js'); \ No newline at end of file diff --git a/isabella_organ/lib/server.js b/isabella_organ/lib/server.js index 4eeda0f..05f51fd 100644 --- a/isabella_organ/lib/server.js +++ b/isabella_organ/lib/server.js @@ -1,32 +1,40 @@ var express = require('express'); var app = express(); -var http = require('http'); var fs = require('fs'); 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.get('/dataroute', function(req, res) { - console.log('get data route'); - next(); +app.get('/data/:name', function(req, res) { + fs.readFile(__dirname + '/data/' + req.params.name + '.json', function(err, data) { + res.json({msg: 'hello world' + req.params.name}); + }); + console.log('read data'); }); app.use(processData); +app.post('/data/:name', function(req, res) { + fs.writeFile(__dirname + '/data/' + req.params.name + '.json', req.body, function(err) { + if (err) console.log(err); + res.send('data posted to new file'); + }); +}); + app.get('/*', function(req, res) { res.status(404).json({msg: 'not found'}); }); app.listen(3000, function() { console.log('server up'); -}); \ No newline at end of file +}); diff --git a/isabella_organ/package.json b/isabella_organ/package.json index 470082c..3406442 100644 --- a/isabella_organ/package.json +++ b/isabella_organ/package.json @@ -4,7 +4,9 @@ "description": "HTTP server with persistance", "main": "index.js", "scripts": { - "test": "./node_modules/mocha/bin/mocha/test" + "test": "node node_modules/argg tests/*.js", + "cover": "istanbul cover --dir reports/coverage node_modules/argg tests/*.js", + "plato": "plato -d reports/plato index.js" }, "repository": { "type": "git", diff --git a/isabella_organ/test/test.js b/isabella_organ/test/test.js index e69de29..07f470e 100644 --- a/isabella_organ/test/test.js +++ b/isabella_organ/test/test.js @@ -0,0 +1,34 @@ +var chai = require('chai'); +var expect = require('chai').expect; +var chaihttp = require('chai-http'); +var fs = require('fs'); + +chai.use(chaihttp); + +require(__dirname + '/../lib/server.js'); + +describe('the http server', function() { + it('should respond to a GET request', function(done) { + chai.request('localhost:3000') + .get('/data/') + .end(function(err, res) { + expect(err).to.eql(null); + // expect(res).to.have.status(200); + expect(res.text).to.eql('{"msg":"not found"}'); + done(); + }); + }); + it('should POST to a new file', function(done) { + chai.request('localhost:3000') + .post('/data/post') + .send('{"msg":"hello world"}') + .end(function(err, res) { + expect(err).to.eql(null); + // expect(res).to.have.status(200); + expect(res.text).to.eql("data posted to new file"); + done(); + }); + }); + +}); + From 9ecdd1f9af8eb5fae4e4a5dea07c73d23eac8a5a Mon Sep 17 00:00:00 2001 From: Isabella Organ Date: Tue, 10 Nov 2015 20:31:21 -0800 Subject: [PATCH 4/6] remove unnecessary file --- isabella_organ/.jscsrc | 90 ------------------------------------------ 1 file changed, 90 deletions(-) delete mode 100644 isabella_organ/.jscsrc diff --git a/isabella_organ/.jscsrc b/isabella_organ/.jscsrc deleted file mode 100644 index 46ccf87..0000000 --- a/isabella_organ/.jscsrc +++ /dev/null @@ -1,90 +0,0 @@ -{ - "requireCurlyBraces": [ - "if", - "else", - "for", - "while", - "do", - "try", - "catch" - ], - "requireOperatorBeforeLineBreak": true, - "requireCamelCaseOrUpperCaseIdentifiers": true, - "maximumLineLength": { - "value": 80, - "allExcept": ["comments", "regex"] - }, - "validateIndentation": 2, - "validateQuoteMarks": "'", - - "disallowMultipleLineStrings": true, - "disallowMixedSpacesAndTabs": true, - "disallowTrailingWhitespace": true, - "disallowSpaceAfterPrefixUnaryOperators": true, - "disallowMultipleVarDecl": true, - "disallowKeywordsOnNewLine": ["else"], - - "requireSpaceAfterKeywords": [ - "if", - "else", - "for", - "while", - "do", - "switch", - "return", - "try", - "catch" - ], - "requireSpaceBeforeBinaryOperators": [ - "=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=", - "&=", "|=", "^=", "+=", - - "+", "-", "*", "/", "%", "<<", ">>", ">>>", "&", - "|", "^", "&&", "||", "===", "==", ">=", - "<=", "<", ">", "!=", "!==" - ], - "requireSpaceAfterBinaryOperators": true, - "requireSpacesInConditionalExpression": true, - "requireSpaceBeforeBlockStatements": true, - "requireSpacesInForStatement": true, - "requireLineFeedAtFileEnd": true, - "requireSpacesInFunctionExpression": { - "beforeOpeningCurlyBrace": true - }, - "disallowSpacesInAnonymousFunctionExpression": { - "beforeOpeningRoundBrace": true - }, - "disallowSpacesInsideObjectBrackets": "all", - "disallowSpacesInsideArrayBrackets": "all", - "disallowSpacesInsideParentheses": true, - - "disallowMultipleLineBreaks": true, - "disallowNewlineBeforeBlockStatements": true, - "disallowKeywords": ["with"], - "disallowSpacesInFunctionExpression": { - "beforeOpeningRoundBrace": true - }, - "disallowSpacesInFunctionDeclaration": { - "beforeOpeningRoundBrace": true - }, - "disallowSpacesInCallExpression": true, - "disallowSpaceAfterObjectKeys": true, - "requireSpaceBeforeObjectValues": true, - "requireCapitalizedConstructors": true, - "requireDotNotation": true, - "requireSemicolons": true, - "validateParameterSeparator": ", ", - - "jsDoc": { - "checkAnnotations": "closurecompiler", - "checkParamNames": true, - "requireParamTypes": true, - "checkRedundantParams": true, - "checkReturnTypes": true, - "checkRedundantReturns": true, - "requireReturnTypes": true, - "checkTypes": true, - "checkRedundantAccess": true, - "requireNewlineAfterDescription": true - } -} \ No newline at end of file From d8855790edb023c33a2277c7a87428d5f8037565 Mon Sep 17 00:00:00 2001 From: Isabella Organ Date: Wed, 11 Nov 2015 07:11:49 -0800 Subject: [PATCH 5/6] changes to server, update tests --- isabella_organ/lib/server.js | 39 +++++++++--------------------------- isabella_organ/test/test.js | 8 +++----- 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/isabella_organ/lib/server.js b/isabella_organ/lib/server.js index 05f51fd..ff78749 100644 --- a/isabella_organ/lib/server.js +++ b/isabella_organ/lib/server.js @@ -2,37 +2,18 @@ var express = require('express'); var app = express(); var fs = require('fs'); -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.get('/data/:name', function(req, res) { - fs.readFile(__dirname + '/data/' + req.params.name + '.json', function(err, data) { - res.json({msg: 'hello world' + req.params.name}); - }); - console.log('read data'); -}); - -app.use(processData); - -app.post('/data/:name', function(req, res) { - fs.writeFile(__dirname + '/data/' + req.params.name + '.json', req.body, function(err) { - if (err) console.log(err); - res.send('data posted to new file'); - }); +app.get('/data/', function(req, res) { + var readStream = fs.createReadStream(__dirname + '/data/post.json'); + res.writeHead(200, {'content-type':'application.json'}); + readStream.pipe(res); }); -app.get('/*', function(req, res) { - res.status(404).json({msg: 'not found'}); +app.post('/data/', function(req, res) { + var writeStream = fs.createWriteStream(__dirname + '/data/post.json'); + req.pipe(writeStream); + req.on('end', function() { + res.json({'msg':'hello world'}); + }); }); app.listen(3000, function() { diff --git a/isabella_organ/test/test.js b/isabella_organ/test/test.js index 07f470e..e29ff9a 100644 --- a/isabella_organ/test/test.js +++ b/isabella_organ/test/test.js @@ -13,19 +13,17 @@ describe('the http server', function() { .get('/data/') .end(function(err, res) { expect(err).to.eql(null); - // expect(res).to.have.status(200); - expect(res.text).to.eql('{"msg":"not found"}'); + expect(res.body).to.eql('{"msg":"get data"}'); done(); }); }); it('should POST to a new file', function(done) { chai.request('localhost:3000') - .post('/data/post') + .post('/data/post.json') .send('{"msg":"hello world"}') .end(function(err, res) { expect(err).to.eql(null); - // expect(res).to.have.status(200); - expect(res.text).to.eql("data posted to new file"); + expect(res.body).to.eql('{"msg":"hello world"}'); done(); }); }); From ea2ef8529de0b20a660fbb82327a056a26a22deb Mon Sep 17 00:00:00 2001 From: Isabella Organ Date: Thu, 21 Apr 2016 15:15:16 -0700 Subject: [PATCH 6/6] update code style --- isabella_organ/gulpfile.js | 12 ++++++------ isabella_organ/index.js | 2 +- isabella_organ/lib/server.js | 12 ++++++------ isabella_organ/test/test.js | 17 ++++++++--------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/isabella_organ/gulpfile.js b/isabella_organ/gulpfile.js index 0842a21..7601c10 100644 --- a/isabella_organ/gulpfile.js +++ b/isabella_organ/gulpfile.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; var gulp = require('gulp'); var mocha = require('gulp-mocha'); @@ -7,7 +7,7 @@ var jshint = require('gulp-jshint'); var appFiles = ['server.js', './lib/**/*.js']; var testFiles = ['./test/**/*.js']; -gulp.task('jshint:test', function() { +gulp.task('jshint:test', () => { return gulp.src(testFiles) .pipe(jshint({ node: true, @@ -21,7 +21,7 @@ gulp.task('jshint:test', function() { .pipe(jshint.reporter('default')); }); -gulp.task('jshint:app', function() { +gulp.task('jshint:app', () => { return gulp.src(appFiles) .pipe(jshint({ node: true @@ -30,12 +30,12 @@ gulp.task('jshint:app', function() { }); -gulp.task('mocha:test', function () { +gulp.task('mocha:test', () => { return gulp.src(testFiles) .pipe(mocha({ - reporter: 'spec'})); + reporter: 'spec' })); }); gulp.task('jshint', ['jshint:test', 'jshint:app']); gulp.task('mocha', ['mocha:test']); -gulp.task('default', ['jshint']); \ No newline at end of file +gulp.task('default', ['jshint']); diff --git a/isabella_organ/index.js b/isabella_organ/index.js index 78f6b62..23d2ada 100644 --- a/isabella_organ/index.js +++ b/isabella_organ/index.js @@ -1,3 +1,3 @@ #!/usr/bin/env node -require(__dirname + '/lib/server.js'); \ No newline at end of file +require(__dirname + '/lib/server.js'); diff --git a/isabella_organ/lib/server.js b/isabella_organ/lib/server.js index ff78749..1cadcae 100644 --- a/isabella_organ/lib/server.js +++ b/isabella_organ/lib/server.js @@ -2,20 +2,20 @@ var express = require('express'); var app = express(); var fs = require('fs'); -app.get('/data/', function(req, res) { +app.get('/data/', (req, res) => { var readStream = fs.createReadStream(__dirname + '/data/post.json'); - res.writeHead(200, {'content-type':'application.json'}); + res.writeHead(200, { 'Content-Type': 'application/json' }); readStream.pipe(res); }); -app.post('/data/', function(req, res) { +app.post('/data/', (req, res) => { var writeStream = fs.createWriteStream(__dirname + '/data/post.json'); req.pipe(writeStream); - req.on('end', function() { - res.json({'msg':'hello world'}); + req.on('end', () => { + res.json({ 'msg': 'hello world' }); }); }); -app.listen(3000, function() { +app.listen(3000, () => { console.log('server up'); }); diff --git a/isabella_organ/test/test.js b/isabella_organ/test/test.js index e29ff9a..75f7b2e 100644 --- a/isabella_organ/test/test.js +++ b/isabella_organ/test/test.js @@ -7,26 +7,25 @@ chai.use(chaihttp); require(__dirname + '/../lib/server.js'); -describe('the http server', function() { - it('should respond to a GET request', function(done) { +describe('the http server', () => { + it('should respond to a GET request', (done) => { chai.request('localhost:3000') .get('/data/') - .end(function(err, res) { + .end((err, res) => { expect(err).to.eql(null); - expect(res.body).to.eql('{"msg":"get data"}'); + expect(res.body).to.eql('{ "msg": "get data "}'); done(); }); }); - it('should POST to a new file', function(done) { + it('should POST to a new file', (done) => { chai.request('localhost:3000') .post('/data/post.json') - .send('{"msg":"hello world"}') - .end(function(err, res) { + .send('{ "msg": "hello world" }') + .end((err, res) => { expect(err).to.eql(null); - expect(res.body).to.eql('{"msg":"hello world"}'); + expect(res.body).to.eql('{ "msg": "hello world"}'); done(); }); }); }); -