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 david_park/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
35 changes: 35 additions & 0 deletions david_park/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var publicFiles = ['index.js', 'public/**/*.js', 'bin/**/*.js'];
var testFiles = ['test/**/*.js'];

gulp.task('mocha:test', function() {
return gulp.src(testFiles, {read:false})
.pipe(mocha({reporter: 'nyan'}));
});

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:public', function() {
return gulp.src(publicFiles)
.pipe(jshint({
node:true
}))
.pipe(jshint.reporter('default'));
})

gulp.task('jshint-mocha', ['jshint:test', 'jshint:public', 'mocha:test']);
gulp.task('default', ['jshint-mocha'])
34 changes: 34 additions & 0 deletions david_park/gulpfile.js~
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var publicFiles = ['index.js', 'public/**/*.js', 'bin/**/*.js'];
var testFiles = ['test/**/*.js'];

gulp.task('mocha:test', function() {
return gulp.src(testFiles, {read:false})
.pipe(mocha({reporter: 'nyan'}));
});

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:public', function() {
return gulp.src(publicFiles)
.pipe(jshint({
node:true
}))
.pipe(jshint.reporter('default'));
})

gulp.task('jshint-mocha', ['jshint:test', 'jshint:public', 'mocha:test']);
gulp.task('default', ['jshint-mocha'])
22 changes: 22 additions & 0 deletions david_park/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "http_server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"chai": "^3.4.0",
"chai-http": "^1.0.0",
"gulp": "^3.9.0",
"gulp-jshint": "^1.12.0",
"gulp-mocha": "^2.1.3",
"mocha": "^2.3.3"
}
}
14 changes: 14 additions & 0 deletions david_park/public/greet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Greetings!</title>
</head>
<body>

<form id="submitName">
<label>Hi! What is your name?</label><input type="text" name="name">
<input type="submit" value="Submit Name"/>
</form>

</body>
</html>
14 changes: 14 additions & 0 deletions david_park/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<!--<link rel="stylesheet"; type="text/css"; href="SOMEFILE.css">-->
<meta charset="UTF-8">
<title>AWESOME HTTP SERVER</title>
</head>
<body>
<h1>AWESOME HTTP SERVER!</h1>
<p>Request Time: Go to localhost:3000/time</p>
<p>Greet: Go to localhost:3000/greet</p>
<p>Greet Name: Go to localhost:3000/greet/name</p>
</body>
</html>
41 changes: 41 additions & 0 deletions david_park/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var http = require('http');
var fs = require('fs');
var ReadStream = require('stream').Readable;

var server = http.createServer(function(req, res) {
var resData = {};
if (req.url === '/' && req.method === 'GET') {
resData.status = 200;
resData.contentType = 'text/html';
resData.data = fs.readFileSync(__dirname + '/public/index.html').toString();
}

if (req.url === '/time' && req.method === 'GET') {
resData.status = 200;
resData.contentType = 'text/html';
resData.data = Date();
//resData.data = JSON.stringify({hello: 'world'});
}

if (req.url === '/greet' && req.method === 'GET') {
resData.status = 200;
resData.contentType = 'text/html';
resData.data = fs.readFileSync(__dirname + '/public/greet.html');
}

/*if (req.url === '/greet/name' && req.method === 'GET') {
res.Data.status = 200;
resData.contentType = "application/json";
resData.data = //JSON.stringify({hello: 'NAME'})
}*/

res.writeHead(resData.status || 404, {
'Content-Type': resData.contentType || 'text/plain'
});
res.write(resData.data || 'not found');
res.end();
});

server.listen(3000, function() {
console.log('server up');
});
34 changes: 34 additions & 0 deletions david_park/test/server_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var chai = require('chai');
var chaihttp = require('chai-http');
chai.use(chaihttp);
var expect = chai.expect;
var fs = require('fs');
require(__dirname + '/../server');

describe('our server', function() {
before(function() {
this.indexFileString = fs.readFileSync(__dirname + '/../public/index.html').toString();
});

it('should be able to get an index', function(done) {
chai.request('localhost:3000')
.get('/')
.end(function(err, res) {
expect(err).to.eql(null);
expect(res).to.have.status(200);
expect(res.text).to.eql(this.indexFileString);
done();
}.bind(this));
});

it('should be able to get the time', function(done) {
chai.request('localhost:3000')
.get('/time')
.end(function(err, res) {
expect(err).to.eql(null);
expect(res).to.have.status(200);
expect(res.text).to.eql(Date());
done();
});
});
});