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
File renamed without changes.
File renamed without changes.
41 changes: 41 additions & 0 deletions isabella_organ/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

var gulp = require('gulp');
var mocha = require('gulp-mocha');
var expect = require('chai').expect;
var jshint = require('gulp-jshint');
var appFiles = ['server.js', './lib/**/*.js'];
var testFiles = ['./test/**/*.js'];

gulp.task('jshint:test', () => {
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', () => {
return gulp.src(appFiles)
.pipe(jshint({
node: true
}))
.pipe(jshint.reporter('default'));
});


gulp.task('mocha:test', () => {
return gulp.src(testFiles)
.pipe(mocha({
reporter: 'spec' }));
});

gulp.task('jshint', ['jshint:test', 'jshint:app']);
gulp.task('mocha', ['mocha:test']);
gulp.task('default', ['jshint']);
3 changes: 3 additions & 0 deletions isabella_organ/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require(__dirname + '/lib/server.js');
21 changes: 21 additions & 0 deletions isabella_organ/lib/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var express = require('express');
var app = express();
var fs = require('fs');

app.get('/data/', (req, res) => {
var readStream = fs.createReadStream(__dirname + '/data/post.json');
res.writeHead(200, { 'Content-Type': 'application/json' });
readStream.pipe(res);
});

app.post('/data/', (req, res) => {
var writeStream = fs.createWriteStream(__dirname + '/data/post.json');
req.pipe(writeStream);
req.on('end', () => {
res.json({ 'msg': 'hello world' });
});
});

app.listen(3000, () => {
console.log('server up');
});
35 changes: 35 additions & 0 deletions isabella_organ/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "isabella_organ",
"version": "1.0.0",
"description": "HTTP server with persistance",
"main": "index.js",
"scripts": {
"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",
"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",
"dependencies": {
"express": "^4.13.3"
},
"devDependencies": {
"chai": "^3.4.1",
"gulp-mocha": "^2.1.3",
"mocha": "^2.3.3"
}
}
31 changes: 31 additions & 0 deletions isabella_organ/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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', () => {
it('should respond to a GET request', (done) => {
chai.request('localhost:3000')
.get('/data/')
.end((err, res) => {
expect(err).to.eql(null);
expect(res.body).to.eql('{ "msg": "get data "}');
done();
});
});
it('should POST to a new file', (done) => {
chai.request('localhost:3000')
.post('/data/post.json')
.send('{ "msg": "hello world" }')
.end((err, res) => {
expect(err).to.eql(null);
expect(res.body).to.eql('{ "msg": "hello world"}');
done();
});
});

});