Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**/*.sw?
**/node_modules
**/data
25 changes: 25 additions & 0 deletions jenny_pollack/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) <2015> <Jenny Pollack>



Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:



The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.



THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
43 changes: 43 additions & 0 deletions jenny_pollack/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var appFiles = ['index.js', 'lib/**/*.js', 'bin/**/*.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('mocha', function(){
return gulp.src(testFiles)
.pipe(jshint({
node: true,
globals: {
describe: true,
it: true
}
}))
.pipe(mocha({reporter: 'spec'}));
});


gulp.task('jshint', ['jshint:test', 'jshint:app']);
gulp.task('default', ['jshint', 'mocha']);
34 changes: 34 additions & 0 deletions jenny_pollack/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require(__dirname + '/lib/server.js');
// var express = require('express');
// var app = express();
// var fs = require('fs');

// var processData = function(req, res, next) {
// var data = '';
// req.on('data', function(newData) {
// data += newData.toString();
// });
// req.on('end', function() {
// req.body = data;
// next();
// });
// };

// app.get('/data/:name', function(req, res) {
// fs.readFile(__dirname + '/data/' + req.params.name + '.json', function(err, data) {
// res.send(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(req.params.name + '.json has been written.');
// });
// });

// app.listen(3000, function() {
// console.log('server up at port 3000');
// });
33 changes: 33 additions & 0 deletions jenny_pollack/lib/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var express = require('express');
var app = express();
var fs = require('fs');

var processData = function(req, res, next) {
var data = '';
req.on('data', function(newData) {
data += newData.toString();
});
req.on('end', function() {
req.body = data;
next();
});
};

app.use(processData);

app.get('/data/:name', function(req, res) {
fs.readFile(__dirname + '/../data/' + req.params.name + '.json', function(err, data) {
res.send(data.toString());
});
});

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("written");
});
});

app.listen(3000, function() {
console.log('server up');
});
25 changes: 25 additions & 0 deletions jenny_pollack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "http_persistence",
"version": "1.0.0",
"description": "an http server that will act as a simple data store",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "test"
},
"author": "Jenny Pollack",
"license": "MIT",
"devDependencies": {
"chai": "^3.4.1",
"chai-http": "^1.0.0",
"gulp-jshint": "^1.12.0",
"gulp-mocha": "^2.1.3",
"mocha": "^2.3.3"
},
"dependencies": {
"body-parser": "^1.14.1",
"express": "^4.13.3"
}
}
26 changes: 26 additions & 0 deletions jenny_pollack/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var fs = require('fs');
var chai = require('chai');
var chaiHttp = require('chai-http');
var express = require('express');
var expect = chai.expect;

chai.use(chaiHttp);


require(__dirname + '/../lib/server');

describe('The server.js file', function (){
it('should respond to a post request by overwriting a file', function(done){
chai.request('localhost:3000')
.post('/greet')
.send({test: 'jello'})
.end(function(err, res){
expect(err).to.eql(null);
expect(res).to.have.status(200);
expect(res.text).to.eql('written');
done();
});
});
});