From 3eba796d7b2227ca2b30ba83944a565dd0987f1e Mon Sep 17 00:00:00 2001
From: DanLombardy
Date: Thu, 5 Nov 2015 10:09:50 -0800
Subject: [PATCH 1/2] Revert "Merge remote-tracking branch
'codefellows-sea-d45-javascript/master'"
This reverts commit 6541c7eb0eb9dc9eecaa07d81d9f25f084d18d9f, reversing
changes made to 29efeb6e84a0fdafba533298d050c5b4a395e64a.
---
.gitignore | 33 ----------
craig_campbell/README.md => README.md | 8 ++-
ansoo_chang/.gitignore | 33 ----------
ansoo_chang/lib/server.js | 27 --------
ansoo_chang/package.json | 22 -------
ansoo_chang/public/index.html | 12 ----
ansoo_chang/public/time.html | 15 -----
ansoo_chang/server.js | 52 ---------------
ansoo_chang/test/server_test.js | 25 --------
craig_campbell/gulpfile.js | 16 -----
craig_campbell/index.js | 3 -
craig_campbell/lib/dateinfo.js | 64 -------------------
craig_campbell/lib/http-server.js | 62 ------------------
craig_campbell/package.json | 37 -----------
craig_campbell/public/index.html | 16 -----
craig_campbell/test/http-server-test.js | 85 -------------------------
jordan_bundy/.gitignore | 5 --
jordan_bundy/gulpfile.js | 44 -------------
jordan_bundy/lib/routes.js | 49 --------------
jordan_bundy/package.json | 23 -------
jordan_bundy/public/index.html | 1 -
jordan_bundy/server.js | 30 ---------
jordan_bundy/test/server_test.js | 36 -----------
kenji_crosland/.gitignore | 1 -
kenji_crosland/gulpfile.js | 35 ----------
kenji_crosland/index.js | 2 -
kenji_crosland/lib/server.js | 52 ---------------
kenji_crosland/package.json | 18 ------
kenji_crosland/public/index.html | 21 ------
kenji_crosland/server.js | 55 ----------------
kenji_crosland/test/test.js | 54 ----------------
ryan_heathers/.jshintrc | 9 ---
ryan_heathers/gulpfile.js | 22 -------
ryan_heathers/index.js | 12 ----
ryan_heathers/package.json | 27 --------
ryan_heathers/requestHandlers.js | 43 -------------
ryan_heathers/router.js | 19 ------
ryan_heathers/server.js | 15 -----
ryan_heathers/test/test.js | 30 ---------
ryan_heathers/views/greet.html | 18 ------
ryan_heathers/views/index.html | 39 ------------
41 files changed, 5 insertions(+), 1165 deletions(-)
delete mode 100644 .gitignore
rename craig_campbell/README.md => README.md (92%)
delete mode 100644 ansoo_chang/.gitignore
delete mode 100644 ansoo_chang/lib/server.js
delete mode 100644 ansoo_chang/package.json
delete mode 100644 ansoo_chang/public/index.html
delete mode 100644 ansoo_chang/public/time.html
delete mode 100644 ansoo_chang/server.js
delete mode 100644 ansoo_chang/test/server_test.js
delete mode 100644 craig_campbell/gulpfile.js
delete mode 100755 craig_campbell/index.js
delete mode 100644 craig_campbell/lib/dateinfo.js
delete mode 100644 craig_campbell/lib/http-server.js
delete mode 100644 craig_campbell/package.json
delete mode 100644 craig_campbell/public/index.html
delete mode 100644 craig_campbell/test/http-server-test.js
delete mode 100644 jordan_bundy/.gitignore
delete mode 100644 jordan_bundy/gulpfile.js
delete mode 100644 jordan_bundy/lib/routes.js
delete mode 100644 jordan_bundy/package.json
delete mode 100644 jordan_bundy/public/index.html
delete mode 100644 jordan_bundy/server.js
delete mode 100644 jordan_bundy/test/server_test.js
delete mode 100644 kenji_crosland/.gitignore
delete mode 100644 kenji_crosland/gulpfile.js
delete mode 100644 kenji_crosland/index.js
delete mode 100644 kenji_crosland/lib/server.js
delete mode 100644 kenji_crosland/package.json
delete mode 100644 kenji_crosland/public/index.html
delete mode 100644 kenji_crosland/server.js
delete mode 100644 kenji_crosland/test/test.js
delete mode 100644 ryan_heathers/.jshintrc
delete mode 100644 ryan_heathers/gulpfile.js
delete mode 100644 ryan_heathers/index.js
delete mode 100644 ryan_heathers/package.json
delete mode 100644 ryan_heathers/requestHandlers.js
delete mode 100644 ryan_heathers/router.js
delete mode 100644 ryan_heathers/server.js
delete mode 100644 ryan_heathers/test/test.js
delete mode 100644 ryan_heathers/views/greet.html
delete mode 100644 ryan_heathers/views/index.html
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index abd644d..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,33 +0,0 @@
-# Logs
-logs
-*.log
-npm-debug.log*
-
-# Runtime data
-pids
-*.pid
-*.seed
-
-# Directory for instrumented libs generated by jscoverage/JSCover
-lib-cov
-
-# Coverage directory used by tools like istanbul
-coverage
-
-# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
-.grunt
-
-# node-waf configuration
-.lock-wscript
-
-# Compiled binary addons (http://nodejs.org/api/addons.html)
-build/Release
-
-# Dependency directory
-# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
-node_modules
-
-# Optional npm cache directory
-.npm
-
-.DS_Store
diff --git a/craig_campbell/README.md b/README.md
similarity index 92%
rename from craig_campbell/README.md
rename to README.md
index ed84eb4..82f1087 100644
--- a/craig_campbell/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
+Vanilla HTTP Server
+===========================
To complete this assignment:
* fork this repository (the sub module for this specific assignment)
* clone down your fork
@@ -9,17 +11,17 @@ To complete this assignment:
Assingment Description
---------------------------
For this assignment you should write an http server in vanilla node that responds to several different routes.
+
The server should respond to a request to /time that will send back the current time of the server.
- * It should also respond to a get request to /greet/name where name is any single word string.
+ * It should also respond to a get request to /greet/name where name is any single word string.
* It should send back a string that greets that name.
* It should also have a separate post request to /greet that takes the name in JSON format.
* There should be tests using chaiHTTP for both routes, as well as a gulpfile/package.json
* You should have an html page that describes the routes implemented by the api available at the root of the server
-
+
Rubric:
* Tests: 4pts
* Routes: 4pts
* Organization and gulpfile/package.json 2pts
-
diff --git a/ansoo_chang/.gitignore b/ansoo_chang/.gitignore
deleted file mode 100644
index abd644d..0000000
--- a/ansoo_chang/.gitignore
+++ /dev/null
@@ -1,33 +0,0 @@
-# Logs
-logs
-*.log
-npm-debug.log*
-
-# Runtime data
-pids
-*.pid
-*.seed
-
-# Directory for instrumented libs generated by jscoverage/JSCover
-lib-cov
-
-# Coverage directory used by tools like istanbul
-coverage
-
-# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
-.grunt
-
-# node-waf configuration
-.lock-wscript
-
-# Compiled binary addons (http://nodejs.org/api/addons.html)
-build/Release
-
-# Dependency directory
-# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
-node_modules
-
-# Optional npm cache directory
-.npm
-
-.DS_Store
diff --git a/ansoo_chang/lib/server.js b/ansoo_chang/lib/server.js
deleted file mode 100644
index 3f5d995..0000000
--- a/ansoo_chang/lib/server.js
+++ /dev/null
@@ -1,27 +0,0 @@
-var http = require('http');
-var fs = require('fs');
-// var ReadStream = require('stream').Readable;
-
-/*
-req is an object containing information about the HTTP request that raised the event. In response to req, you use res to send back the desired HTTP response.
-*/
-
-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();
- }
-
- // res.writeHead({
- // status: resData.status || 400,
- // 'Content-Type': resData.contentType || 'text/plain'
- // });
-
-
-});
-
-server.listen(3000, function() {
- console.log('server up!');
-});
diff --git a/ansoo_chang/package.json b/ansoo_chang/package.json
deleted file mode 100644
index eb6698e..0000000
--- a/ansoo_chang/package.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "name": "httpserver",
- "version": "1.0.0",
- "description": "create an http server",
- "main": "index.js",
- "directories": {
- "test": "test"
- },
- "scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
- },
- "author": "",
- "license": "MIT",
- "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"
- }
-}
diff --git a/ansoo_chang/public/index.html b/ansoo_chang/public/index.html
deleted file mode 100644
index 9ab70b9..0000000
--- a/ansoo_chang/public/index.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
- Test
-
-
-Test!
-
-This is a test!
-
-
-
diff --git a/ansoo_chang/public/time.html b/ansoo_chang/public/time.html
deleted file mode 100644
index d3e9e66..0000000
--- a/ansoo_chang/public/time.html
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
- Time
-
-
-
-
-
-
-
-
-
diff --git a/ansoo_chang/server.js b/ansoo_chang/server.js
deleted file mode 100644
index 988bca5..0000000
--- a/ansoo_chang/server.js
+++ /dev/null
@@ -1,52 +0,0 @@
-var http = require('http');
-var fs = require('fs');
-var url = require('url');
-
-/*
-req is an object containing information about the HTTP request that raised the event. In response to req, you use res to send back the desired HTTP response.
-*/
-
-var server = http.createServer(function(req, res) {
- // create response data object
- var resData = {}
- var name = req.url.split('/')[2];
- var queryObj = url.parse(req.url, true)
-
- if (req.url === '/' && req.method === 'GET') {
- resData.status = 200;
- resData.contentType = 'text/html';
- resData.data = fs.readFileSync(__dirname + '/public/index.html').toString();
- }
-
- // respond to a request to /time that will send back the current time of the server.
- if (req.url === '/time' && req.method === 'GET') {
- resData.status = 200;
- resData.contentType = 'text/html';
- resData.data = new Date().toString();
- }
-
- // respond to a get request to /greet/name and send back a string that greets that name
- if (req.url === '/greet/' + name && req.method === 'GET') {
- resData.status = 200;
- resData.contentType = 'text/html';
- resData.data = 'Hello ' + name;
- }
-
- // post request to /greet that takes the name in JSON format
- if (req.url === '/greet/' + name && req.method === 'POST') {
- resData.status = 200;
- resData.contentType = 'application/json';
- resData.data = JSON.stringify({Hello: name});
- }
-
- res.writeHead(resData.status || 400, {
- 'Content-Type': resData.contentType || 'text/plain'
- });
-
- res.write(resData.data || 'not found');
- res.end();
-});
-
- server.listen(3000, function() {
- console.log('server up!');
-});
diff --git a/ansoo_chang/test/server_test.js b/ansoo_chang/test/server_test.js
deleted file mode 100644
index f77a4ab..0000000
--- a/ansoo_chang/test/server_test.js
+++ /dev/null
@@ -1,25 +0,0 @@
-var chai = require('chai');
-var chaihttp = require('chai-http');
-chai.use(chaihttp);
-var expect = chai.expect;
-var fs = require('fs');
-require(__dirname + '/../server.js');
-
-describe('http 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')
- //debugger;
- .get('/')
- .end(function(err, res) {
- // debugger;
- expect(err).to.eq(null);
- expect(res).to.have.status(200);
- expect(res.text).to.eql(this.indexFileString);
- done();
- }.bind(this));
- });
-});
diff --git a/craig_campbell/gulpfile.js b/craig_campbell/gulpfile.js
deleted file mode 100644
index 48eac2e..0000000
--- a/craig_campbell/gulpfile.js
+++ /dev/null
@@ -1,16 +0,0 @@
-var gulp = require('gulp');
-var jshint = require('gulp-jshint');
-var mocha = require('gulp-mocha');
-
-gulp.task('default', ['jshint', 'test']);
-
-gulp.task('jshint', function(){
- gulp.src(['gulpfile.js', 'index.js', 'test/*.js', 'lib/*.js'])
- .pipe(jshint())
- .pipe(jshint.reporter('jshint-stylish'));
-});
-
-gulp.task('test', ['jshint'], function(){
- gulp.src('test/*test.js')
- .pipe(mocha({reporter: 'nyan'}));
-});
diff --git a/craig_campbell/index.js b/craig_campbell/index.js
deleted file mode 100755
index e89a6c0..0000000
--- a/craig_campbell/index.js
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env node
-
-var start = require(__dirname + '/lib/http-server.js');
diff --git a/craig_campbell/lib/dateinfo.js b/craig_campbell/lib/dateinfo.js
deleted file mode 100644
index 7b236a8..0000000
--- a/craig_campbell/lib/dateinfo.js
+++ /dev/null
@@ -1,64 +0,0 @@
-'use strict';
-// a library of sorts, written by Craig Campbell (craig.campbell8@gmail.com)
-
-module.exports = exports = {
-
- newDate : function() {
-
- return new Date().toString();
- },
-
- getTheYear: function() {
-
- return new Date().getFullYear().toString();
- },
-
- getTheMonth: function(){
-
- var month = (new Date().getMonth() + 1).toString(); // add 1 because months go from 0-11 not 1-12
- if ( Number(month) < 10) {
- month = "0" + month;
- }
- return month.toString();
- },
-
- getTheDay: function() {
-
- var day = new Date().getDate().toString();
- if ( Number(day) < 10) {
- day = "0" + day;
- }
- return day.toString();
- },
-
- getTheHours: function() {
-
- var hours = new Date().getHours().toString();
- if ( Number(hours) < 10) {
- hours = "0" + hours;
- }
- return hours.toString();
-
- },
-
- getTheMinutes: function(){
-
- var minutes = new Date().getMinutes().toString();
- if ( Number(minutes) < 10) {
- minutes = "0" + minutes;
- }
- return minutes.toString();
- },
-
- getTheSeconds: function(){
-
- var seconds = new Date().getSeconds().toString();
- if ( Number(seconds) < 10) {
- seconds = "0" + seconds;
- }
- return seconds.toString();
-
- }
-
- };
-
diff --git a/craig_campbell/lib/http-server.js b/craig_campbell/lib/http-server.js
deleted file mode 100644
index 274c104..0000000
--- a/craig_campbell/lib/http-server.js
+++ /dev/null
@@ -1,62 +0,0 @@
-'use strict';
-
-var dateinfo = require('./dateinfo.js');
-var fs = require('fs');
-var http = require('http');
-var port = 3000;
-
-var server = http.createServer(function(req, res){
- var name = req.url.slice(7);
-
- if (req.method === 'GET' && req.url === '/') {
- fs.readFile(__dirname + '/../public/index.html', function(err, data){
- res.writeHead(200, {'Content-Type' : 'text/html'});
- if (err) return console.log(err);
- res.write(data, 'utf-8');
- return res.end();
- });
- }
-
- if (req.method === "GET" && req.url === '/time'){
- res.writeHead(200, {
- 'Content-Type' : 'text/plain'
- });
-
- res.write(
- "The current date is: " + dateinfo.getTheMonth() + '-' + dateinfo.getTheDay() + '-' + dateinfo.getTheYear() + ' and the current time is: ' + dateinfo.getTheHours() + ':' + dateinfo.getTheMinutes() + ':' + dateinfo.getTheSeconds() + '.\n\nThis can also be expressed as '+ Date.now().toString() + ' milliseconds since Janury 1, 1970. \n\nAdditionally, this can be expressed as: ' + dateinfo.newDate()
- );
- return res.end();
- }
-
- if (req.method === 'GET' && req.url === '/greet/' + name){
- res.writeHead(200, {
- 'Content-Type' : 'text/plain'
- });
- res.write("Well hello there, " + name);
- return res.end();
- }
-
- if (req.method === "POST" && req.url === ('/greet')){
-
- req.on('data', function(data){
- var parsed = JSON.parse(data.toString());
- console.log(parsed);
- res.writeHead(200, { 'Content-Type' : 'text/plain'});
- res.write('Howdy, ' + parsed.name + '!');
- return res.end();
- });
- }
-
- if ((req.method === 'GET' && req.url !== '/' && req.url !== '/greet/' + name && req.url !== '/time' ) || (req.method === 'POST' && req.url !== '/greet') ){
- res.writeHead(404, {
- 'Content-Type' : 'text/plain'
- });
- res.write("You must be trippin! Ain't no such resource here!");
- res.end();
- }
-
-}); //end createServer
-
-server.listen(port, function(){
- console.log("The server is running on port: ", port);
-});
diff --git a/craig_campbell/package.json b/craig_campbell/package.json
deleted file mode 100644
index 6e8d099..0000000
--- a/craig_campbell/package.json
+++ /dev/null
@@ -1,37 +0,0 @@
-{
- "name": "http-server",
- "version": "1.0.0",
- "description": "simple http server",
- "main": "index.js",
- "directories": {
- "test": "test"
- },
- "scripts": {
- "test": "./node_modules/mocha/bin/mocha test",
- "start": "./index.js",
- "motivator": "echo 'CRAIG, YOU CAN DO IT!'"
- },
- "repository": {
- "type": "git",
- "url": "git+https://github.com/craigaaroncampbell/http-server.git"
- },
- "keywords": [
- "http",
- "server"
- ],
- "author": "craigaaroncampbell@gmail.com",
- "license": "MIT",
- "bugs": {
- "url": "https://github.com/craigaaroncampbell/http-server/issues"
- },
- "homepage": "https://github.com/craigaaroncampbell/http-server#readme",
- "devDependencies": {
- "chai": "^3.4.0",
- "chai-http": "^1.0.0",
- "gulp": "^3.9.0",
- "gulp-jshint": "^1.12.0",
- "gulp-mocha": "^2.1.3",
- "jshint-stylish": "^2.0.1",
- "mocha": "^2.3.3"
- }
-}
diff --git a/craig_campbell/public/index.html b/craig_campbell/public/index.html
deleted file mode 100644
index 2ca45e0..0000000
--- a/craig_campbell/public/index.html
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
- This is basically a README
-
-
-
-A simple HTTP server. GET requests to /greet/[somename] will greet the user by whaterver is typed after /greet/.
-
-GET Requests to /time will give the user the curent time in several formats.
-
-POST requests to /greet will greet the user IF the POST sends JSON in the form '{"name":"[somename]"}' where [somename] is a string.
-
-
-
diff --git a/craig_campbell/test/http-server-test.js b/craig_campbell/test/http-server-test.js
deleted file mode 100644
index e9481c0..0000000
--- a/craig_campbell/test/http-server-test.js
+++ /dev/null
@@ -1,85 +0,0 @@
-var chai = require('chai');
-var expect = chai.expect;
-var fs = require('fs');
-var chaiHttp = require('chai-http');
-
-chai.use(chaiHttp);
-
-require(__dirname + '/../lib/http-server.js');
-
-describe('this server', function(){
-
- before(function(){
- this.indexFileString = fs.readFileSync(__dirname + '/../public/index.html').toString();
- this.name = "kenji";
- this.JSON = {"name": "bob"};
-
- });
-
- it('should respond to root level requests by serving index.html', 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 greet "xxx" someone for requests to /greet/xxx', function(done){
- chai.request('localhost:3000')
- .get('/greet/' + this.name)
- .end(function(err, res){
- expect(err).to.eql(null);
- expect(res).to.have.status(200);
- expect(res.text).to.eql('Well hello there, ' + this.name);
- done();
- }.bind(this));
-
- });
-
- it('should respond to GET requests to /time', function(){
- chai.request('localhost:3000')
- .get('/time')
- .end(function(err, res){
- expect(err).to.eql(null);
- expect(res).to.have.status(200);
- done();
- });
-
- });
-
- it('should respond to GET requests at /greet with a 404 (because this route is reserved for POST' , function(){
- chai.request('localhost:3000')
- .get('/greet')
- .end(function(err, res){
- expect(err).to.eql(null);
- expect(res).to.have.status(404);
- done();
- });
- });
-
- it('should respond to POST requests at /greet when JSON data is sent with a message greeting the value of "name" in the JSON' , function(done){
- chai.request('localhost:3000')
- .post('/greet')
- .send(this.JSON)
- .end(function(err, res){
- expect(err).to.eql(null);
- expect(res).to.have.status(200);
- expect(res.text).to.eql("Howdy, " + this.JSON.name + '!');
- done();
- }.bind(this));
- });
-
-
- it('should respond with 404 to all other requests', function(done){
- chai.request('localhost:3000')
- .get('/someotherpath')
- .end(function(err, res){
- expect(err).to.eql(null);
- expect(res).to.have.status(404);
- done();
- }.bind(this));
- });
-});
diff --git a/jordan_bundy/.gitignore b/jordan_bundy/.gitignore
deleted file mode 100644
index 00e302b..0000000
--- a/jordan_bundy/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
-.
-..
-.DS_Store
-node_modules
-
diff --git a/jordan_bundy/gulpfile.js b/jordan_bundy/gulpfile.js
deleted file mode 100644
index af1e4ce..0000000
--- a/jordan_bundy/gulpfile.js
+++ /dev/null
@@ -1,44 +0,0 @@
-var gulp = require('gulp');
-var jshint = require('gulp-jshint');
-var mocha = require('gulp-mocha');
-var appFiles = ['index.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('mocha:test', function() {
- return gulp.src(testFiles)
- .pipe(mocha({
- read: false,
- reporter: 'nyan'
- }))
-});
-
-gulp.task('watch', function() {
- gulp.watch(['./**/*', '!./package.json'], ['jshint', 'mocha']);
-});
-
-gulp.task('jshint', ['jshint:test', 'jshint:app']);
-gulp.task('mocha', ['mocha:test']);
-gulp.task('default', ['jshint', 'mocha', 'watch']);
-
diff --git a/jordan_bundy/lib/routes.js b/jordan_bundy/lib/routes.js
deleted file mode 100644
index 889242c..0000000
--- a/jordan_bundy/lib/routes.js
+++ /dev/null
@@ -1,49 +0,0 @@
-var fs = require('fs');
-
-var routes = {};
-var routeList = '';
-
-routes['/'] = {
- GET: {
- status: 200,
- contentType: 'text/html',
- data: fs.readFileSync(__dirname + '/../public/index.html').toString()
- }
-};
-
-routes['/name'] = {
- GET: {
- status: 200,
- contentType: 'text/plain',
- data: 'Hello there Mr. '
- },
- POST: {
-
- }
-};
-
-routes['/time'] = {
- GET: {
- status: 200,
- contentType: 'text/plain',
- data: new Date().toString()
- }
-};
-
-Object.keys(routes).forEach(function(route) {
- routeList += '' + route + ' ';
-});
-
-fs.writeFileSync(__dirname + '/../public/index.html', ''+
- ''+
- ''+
- ''+
- ''+
- 'Hello World '+
- routeList +
- ''+
- ''
- );
-
-module.exports = routes;
-
diff --git a/jordan_bundy/package.json b/jordan_bundy/package.json
deleted file mode 100644
index 1356c6c..0000000
--- a/jordan_bundy/package.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "name": "http_server_assignment",
- "version": "0.1.0",
- "description": "Assignment to create a vanilla http server",
- "main": "server.js",
- "scripts": {
- "test": "mocha",
- "start": "node server.js"
- },
- "repository": {
- "type": "git",
- "url": "git+ssh://git@github.com/dabellator/create_an_http_server.git"
- },
- "author": "Jordan Bundy",
- "license": "MIT",
- "bugs": {
- "url": "https://github.com/dabellator/create_an_http_server/issues"
- },
- "homepage": "https://github.com/dabellator/create_an_http_server#readme",
- "devDependencies": {
- "nodemon": "^1.8.1"
- }
-}
diff --git a/jordan_bundy/public/index.html b/jordan_bundy/public/index.html
deleted file mode 100644
index 9ae4fac..0000000
--- a/jordan_bundy/public/index.html
+++ /dev/null
@@ -1 +0,0 @@
-Hello World / /name /time
\ No newline at end of file
diff --git a/jordan_bundy/server.js b/jordan_bundy/server.js
deleted file mode 100644
index 21d1b75..0000000
--- a/jordan_bundy/server.js
+++ /dev/null
@@ -1,30 +0,0 @@
-var http = require('http');
-var fs = require('fs');
-var routes = require('./lib/routes');
-
-var server = http.createServer(function(req, res) {
- var resData = {};
- var reqUrl = req.url;
- var name;
-
- if (req.url.lastIndexOf('/') > 0) {
- reqUrl = req.url.slice(0, req.url.lastIndexOf('/'));
- name = req.url.slice(req.url.lastIndexOf('/') + 1);
- }
-
- if (Object.keys(routes).indexOf(reqUrl) !== -1 && Object.keys(routes[reqUrl]).indexOf(req.method) !== -1) {
- resData = routes[reqUrl][req.method];
- if (name) resData.data = resData.data + name;
- }
-
- res.writeHead(resData.status || 404, {
- 'Content-Type': resData.contentType,
- });
- res.write(resData.data || 'not found');
- res.end();
-});
-
-server.listen(3000, function() {
- console.log('Server running, yo');
-});
-
diff --git a/jordan_bundy/test/server_test.js b/jordan_bundy/test/server_test.js
deleted file mode 100644
index b40b701..0000000
--- a/jordan_bundy/test/server_test.js
+++ /dev/null
@@ -1,36 +0,0 @@
-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 take a post value', function(done) {
- chai.request('localhost:3000')
- .post('/name')
- .field('name', 'Jordan')
- .end(function(err, res) {
- expect(res.text).to.eql('{"name": "Jordan"}');
- done();
- });
- });
-});
-
-
-
diff --git a/kenji_crosland/.gitignore b/kenji_crosland/.gitignore
deleted file mode 100644
index 07e6e47..0000000
--- a/kenji_crosland/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/node_modules
diff --git a/kenji_crosland/gulpfile.js b/kenji_crosland/gulpfile.js
deleted file mode 100644
index 3c1a236..0000000
--- a/kenji_crosland/gulpfile.js
+++ /dev/null
@@ -1,35 +0,0 @@
-var gulp = require('gulp');
-var jshint = require('gulp-jshint');
-var mocha = require('gulp-mocha');
-var appFiles = ['index.js', './lib/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,
- 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', ['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']);
diff --git a/kenji_crosland/index.js b/kenji_crosland/index.js
deleted file mode 100644
index 3eb8429..0000000
--- a/kenji_crosland/index.js
+++ /dev/null
@@ -1,2 +0,0 @@
-'use strict';
-var server = require(__dirname + "/lib/server").server;
diff --git a/kenji_crosland/lib/server.js b/kenji_crosland/lib/server.js
deleted file mode 100644
index bc867f1..0000000
--- a/kenji_crosland/lib/server.js
+++ /dev/null
@@ -1,52 +0,0 @@
-var http = require('http');
-var url = require('url');
-var fs = require('fs');
-
-var server = module.exports.server = http.createServer(function(request, response) {
-//Create a path array variable to split the URL into segments
-var pathArray = request.url.split('/');
-
-if (request.url === '/' && request.method === 'GET' ){
- fs.readFile('./public/index.html', function(err, data) {
- if (err) throw err;
- response.writeHead(200, {"Content-Type": "text/html"});
- var htmlString = data.toString().replace("{{Name}}", "");
- response.write(htmlString);
- response.end();
- });
-}
-if (pathArray[1] === 'greet' && request.method === 'GET') {
- console.log(pathArray);
- fs.readFile('./public/index.html', function(err, data) {
- if (err) throw err;
- console.log('greet!');
- response.writeHead(200, {"Content-Type": "text/html"});
- var htmlString = data.toString().replace("{{Name}}", " " + pathArray[2]);
- response.write(htmlString);
- response.end();
- });
-}
-
-if (pathArray[1] === 'greet' && request.method === 'POST') {
- console.log("POST");
- var body = "";
- //Got some help here https://davidwalsh.name/nodejs-http-request
- request.on('data', function(chunk){
- console.log(chunk);
- body+= chunk;
- });
- //And here: http://stackoverflow.com/questions/15427220/how-to-handle-post-request-in-node-js
- request.on('end', function(){
- var parsed = JSON.parse(body);
- response.writeHead(200, {"Content-Type": "application/json"});
- console.log("Hello: " + parsed.name);
- response.write(JSON.stringify(parsed));
- response.end();
- });
-}
-
-});
-
-server.listen(3000, function(){
- console.log('server is up!');
-});
diff --git a/kenji_crosland/package.json b/kenji_crosland/package.json
deleted file mode 100644
index 7f18e27..0000000
--- a/kenji_crosland/package.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "name": "kenji_crosland_vanilla_http",
- "version": "1.0.0",
- "description": "A vanilla http server",
- "main": "index.js",
- "scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
- },
- "author": "Kenji Crosland",
- "license": "MIT",
- "devDependencies": {
- "chai": "^3.4.0",
- "chai-http": "^1.0.0",
- "gulp": "^3.9.0",
- "gulp-jshint": "^1.12.0",
- "gulp-mocha": "^2.1.3"
- }
-}
diff --git a/kenji_crosland/public/index.html b/kenji_crosland/public/index.html
deleted file mode 100644
index 6bc23e0..0000000
--- a/kenji_crosland/public/index.html
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
- Hello{{Name}}!
-
- Here are the amazing things you can do with the app!
-
-
- Type in http://localhost:3000/greet/(anyname) and we will greet you by that name! Example: http://localhost:3000/greet/Cornelius
-
-
- Do a post request with a JSON object to http://localhost:3000/greet/ using superagent (Example: superagent localhost:3000/greet post '{"name": "Cornelius"}' ), and you will get a JSON string back!
-
-
-
-
-
-
diff --git a/kenji_crosland/server.js b/kenji_crosland/server.js
deleted file mode 100644
index 0685646..0000000
--- a/kenji_crosland/server.js
+++ /dev/null
@@ -1,55 +0,0 @@
-'use strict';
-var http = require('http');
-var url = require('url');
-var fs = require('fs');
-
-var server = http.createServer(function(request, response) {
-//Create a path array variable to split the URL into segments
-var pathArray = request.url.split('/');
-
-if (request.url === '/' && request.method === 'GET' ){
- fs.readFile('./public/index.html', function(err, data) {
- if (err) throw err;
- response.writeHead(200, {"Content-Type": "text/html"});
- var htmlString = data.toString().replace("{{Name}}", "");
- response.write(htmlString);
- response.end();
- });
-}
-if (pathArray[1] === 'greet' && request.method === 'GET') {
- console.log(pathArray);
- fs.readFile('./public/index.html', function(err, data) {
- if (err) throw err;
- console.log('greet!');
- //Need an if statement
- response.writeHead(200, {"Content-Type": "text/html"});
- var htmlString = data.toString().replace("{{Name}}", " " + pathArray[2]);
- response.write(htmlString);
- response.end();
- });
-}
-
-if (pathArray[1] === 'greet' && request.method === 'POST') {
- console.log("POST");
- var body = "";
- //Got some help here https://davidwalsh.name/nodejs-http-request
- request.on('data', function(chunk){
- console.log(chunk);
- body+= chunk;
- });
- //And here: http://stackoverflow.com/questions/15427220/how-to-handle-post-request-in-node-js
- request.on('end', function(){
- var parsed = JSON.parse(body);
- response.writeHead(200, {"Content-Type": "application/json"});
- console.log("Hello: " + parsed.name);
- response.write(JSON.stringify(parsed));
- response.end();
- });
-}
-
-});
-
-server.listen(3000, function(){
- console.log('server is up!');
-});
-
diff --git a/kenji_crosland/test/test.js b/kenji_crosland/test/test.js
deleted file mode 100644
index 262c77e..0000000
--- a/kenji_crosland/test/test.js
+++ /dev/null
@@ -1,54 +0,0 @@
-'use strict';
-var chai = require('chai');
-var chaiHttp = require('chai-http');
-chai.use(chaiHttp);
-var expect = chai.expect;
-require(__dirname + '/../lib/server.js');
-var fs = require('fs');
-
-describe('a GET request to to "/"', function(){
-
- it('should respond with an html file', function(done){
- chai.request('http://localhost:3000')
- .get('/')
- .end(function(err, res){
- expect(res).to.have.status(200);
- expect(res.text).to.include('');
- //expect(res.text).to.equal(this.htmlIndex);
- done();
- }.bind(this));
- });
-});
-
-describe('a GET request to greet/name', function() {
-
- describe('when the name is a single word string', function(){
-
- it('should send back a string that greets that name', function(done){
- chai.request('http://localhost:3000')
- .get('/greet/Cornelius')
- .end(function(err, res){
- expect(res.text).to.include('Cornelius');
- expect(res.text).to.not.include('{{Names}}');
- expect(res).to.have.status(200);
- done();
- });
- });
- });
-});
-
-describe('a POST request to /greet', function(){
-
- it('should be able to take a name in JSON format', function(done){
- chai.request('http://localhost:3000')
- .post('/greet')
- .send({ name: 'Cornelius' })
- .end(function(res){
- expect(res.text).to.equal('{"name":"Cornelius"}');
- expect(res).to.have.status(200);
- done();
- });
- });
-});
-
-
diff --git a/ryan_heathers/.jshintrc b/ryan_heathers/.jshintrc
deleted file mode 100644
index 7fa093f..0000000
--- a/ryan_heathers/.jshintrc
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "node": "true",
- "globals": {
- "describe": true,
- "it": true,
- "before": true,
- "after": true
- }
-}
diff --git a/ryan_heathers/gulpfile.js b/ryan_heathers/gulpfile.js
deleted file mode 100644
index fbf2874..0000000
--- a/ryan_heathers/gulpfile.js
+++ /dev/null
@@ -1,22 +0,0 @@
-var gulp = require('gulp');
-var jshint = require('gulp-jshint');
-var mocha = require('gulp-mocha');
-
-var files = ['server.js', 'test/*.js'];
-
-gulp.task('jshint', function() {
- return gulp.src(files)
- .pipe(jshint())
- .pipe(jshint.reporter('default'));
-});
-
-gulp.task('mocha', ['jshint'], function() {
- return gulp.src(files)
- .pipe(mocha());
-});
-
-gulp.task('watch', function() {
- gulp.watch(files, ['jshint', 'mocha']);
-});
-
-gulp.task('default', ['jshint', 'mocha']);
diff --git a/ryan_heathers/index.js b/ryan_heathers/index.js
deleted file mode 100644
index 5064184..0000000
--- a/ryan_heathers/index.js
+++ /dev/null
@@ -1,12 +0,0 @@
-var server = require('server');
-var router = require('router');
-var requestHandlers = require('requestHandlers');
-
-var route = {};
-route['/'] = requestHandlers.index;
-route['/time'] = requestHandlers.time;
-route['/greet'] = requestHandlers.greet;
-route['/postGreeting'] = requestHandlers.postGreeting;
-
-server.start(router.router, route);
-
diff --git a/ryan_heathers/package.json b/ryan_heathers/package.json
deleted file mode 100644
index 3deb80d..0000000
--- a/ryan_heathers/package.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "name": "http_server",
- "version": "0.1.0",
- "description": "simple http server",
- "main": "server.js",
- "scripts": {
- "test": "echo \"Error: no test specified\" && exit 1",
- "start": "node server.js"
- },
- "repository": {
- "type": "git",
- "url": "git+https://github.com/ryanheathers/create_tcp_server.git"
- },
- "author": "Ryan Heathers",
- "license": "ISC",
- "bugs": {
- "url": "https://github.com/ryanheathers/create_tcp_server/issues"
- },
- "homepage": "https://github.com/ryanheathers/create_tcp_server#readme",
- "devDependencies": {
- "chai": "^3.4.0",
- "chai-http": "^1.0.0",
- "gulp": "^3.9.0",
- "gulp-jshint": "^1.12.0",
- "gulp-mocha": "^2.1.3"
- }
-}
diff --git a/ryan_heathers/requestHandlers.js b/ryan_heathers/requestHandlers.js
deleted file mode 100644
index 3cdca2e..0000000
--- a/ryan_heathers/requestHandlers.js
+++ /dev/null
@@ -1,43 +0,0 @@
-var fs = require('fs');
-var url = require('url');
-
-function index(response) {
- var content = fs.readFileSync(__dirname + "/views/index.html");
- response.writeHead(200, {"Content-Type": "text/html"});
- response.write(content);
- response.end();
-}
-
-function time(response) {
- var time = new Date().getTime();
- var date = new Date(time);
- response.write("The current server time is: " + date);
- response.end();
-}
-
-function greet(response) {
- var content = fs.readFileSync(__dirname + "/views/greet.html");
- response.writeHead(200, {"Content-Type": "text/html"});
- response.write(content);
- response.end();
-}
-
-function greetName(response, name) {
- response.write("How's your day going, " + name.toUpperCase() + '?');
- response.end();
-}
-
-function postGreeting(response, request) {
- var query = url.parse(request.url, true).query;
- var json = JSON.stringify(query);
-
- response.writeHead(200, {"Content-Type": "text/plain"});
- response.write("Thanks for your submission of: " + query.name);
- response.end();
-}
-
-exports.index = index;
-exports.time = time;
-exports.greet = greet;
-exports.greetName = greetName;
-exports.postGreeting = postGreeting;
diff --git a/ryan_heathers/router.js b/ryan_heathers/router.js
deleted file mode 100644
index 2315087..0000000
--- a/ryan_heathers/router.js
+++ /dev/null
@@ -1,19 +0,0 @@
-var requestHandlers = require('requestHandlers');
-
-function router(route, pathname, response, request) {
- if (pathname.match(/^\/greet\/.*/) && request.method === 'GET') {
- var name = pathname.substring(7);
- requestHandlers.greetName(response, name);
- }
- else if (typeof route[pathname] === 'function' ) {
- route[pathname](response, request);
- }
- else {
- console.log("No request handler found for " + pathname);
- response.writeHead(404, {"Content-Type": "text/plain"});
- response.write("404 Not Found");
- response.end();
- }
-}
-
-exports.router = router;
diff --git a/ryan_heathers/server.js b/ryan_heathers/server.js
deleted file mode 100644
index 8e2cc1c..0000000
--- a/ryan_heathers/server.js
+++ /dev/null
@@ -1,15 +0,0 @@
-var http = require('http');
-var url = require('url');
-
-function start(router, route) {
- function onRequest(request, response) {
- var pathname = url.parse(request.url).pathname;
- router(route, pathname, response, request);
- }
-
- var server = http.createServer(onRequest).listen('3000');
- console.log('Server running');
-}
-
-exports.start = start;
-
diff --git a/ryan_heathers/test/test.js b/ryan_heathers/test/test.js
deleted file mode 100644
index 8a697ad..0000000
--- a/ryan_heathers/test/test.js
+++ /dev/null
@@ -1,30 +0,0 @@
-var chai = require('chai');
-var chaihttp = require('chai-http');
-chai.use(chaihttp);
-var expect = chai.expect;
-var fs = require('fs');
-require(__dirname + '/../server');
-
-describe('test /time route', function() {
- it('should find a valid page', function(done) {
- chai.request('localhost:3000')
- .get('/time')
- .end(function(err, res) {
- expect(err).to.eql(null);
- expect(res).to.have.status(200);
- done();
- }.bind(this));
- });
-});
-
-describe('test /greet route', function() {
- it('should find a valid page', function(done) {
- chai.request('localhost:3000')
- .get('/greet/bert')
- .end(function(err, res) {
- expect(err).to.eql(null);
- expect(res).to.have.status(200);
- done();
- }.bind(this));
- });
-});
diff --git a/ryan_heathers/views/greet.html b/ryan_heathers/views/greet.html
deleted file mode 100644
index bf5203e..0000000
--- a/ryan_heathers/views/greet.html
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
- Greet
-
-
-
-
-
-
-
-
diff --git a/ryan_heathers/views/index.html b/ryan_heathers/views/index.html
deleted file mode 100644
index 15a9fb0..0000000
--- a/ryan_heathers/views/index.html
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
-
-
-
- Home
-
-
-
-
-
- Available Routes
-
-
- /time
-
-
- Will show you the current time
-
-
-
-
- /greet
-
-
- Allows you to submit a new name
-
-
-
-
- /greet/name
-
-
- Will greet the name you provide
-
-
-
-
-
From 9ad47289b55a65a8ae94dd54d4d8933e84c1bac6 Mon Sep 17 00:00:00 2001
From: DanLombardy
Date: Thu, 5 Nov 2015 11:56:27 -0800
Subject: [PATCH 2/2] add testing for all routes
---
dan_lombardy/index.js | 2 +-
dan_lombardy/lib/requestHandlers.js | 25 +++++----
dan_lombardy/test/server-test.js | 81 ++++++++++++++++++++---------
3 files changed, 71 insertions(+), 37 deletions(-)
diff --git a/dan_lombardy/index.js b/dan_lombardy/index.js
index 507b0ee..7251440 100644
--- a/dan_lombardy/index.js
+++ b/dan_lombardy/index.js
@@ -5,7 +5,7 @@ var router = require(__dirname + "/lib/router");
var requestHandlers = require(__dirname + "/lib/requestHandlers");
var handle = {};
-var hande = {};
+
handle["/"] = requestHandlers.index;
handle["/index"] = requestHandlers.index;
handle["/server"] = requestHandlers.serverTime;
diff --git a/dan_lombardy/lib/requestHandlers.js b/dan_lombardy/lib/requestHandlers.js
index aed1071..3cf234c 100644
--- a/dan_lombardy/lib/requestHandlers.js
+++ b/dan_lombardy/lib/requestHandlers.js
@@ -1,15 +1,16 @@
"use strict";
+
var querystring = require('querystring');
var fs = require('fs');
-var postedNames = {name: ["billy", "john"]};
+var postedNames = {name: ["billy", "john", "ev"]};
function index(response){
var resData = {};
resData.status = 200;
- resData.contentType = "text.html";
resData.data = fs.readFileSync(__dirname + '/../public/index.html').toString();
+ response.setHeader("Content-Type", "text/html");
response.write(resData.data);
console.log("Index written to stream");
response.end();
@@ -19,7 +20,7 @@ function index(response){
function name(response){
var resData = {};
resData.status = 200;
- resData.contentType = "application/json";
+ response.setHeader("Content-Type", "text/plain");
resData.data = JSON.stringify(postedNames.name[postedNames.name.length-1]);
response.write("hello " + resData.data);
console.log("Name and greeting written to stream");
@@ -30,7 +31,7 @@ function name(response){
function greetPost(response, request){
- var resData = "Thanks for posting your name as" + request.data;
+ var message;
request.on("data", function(data){
var reqData = JSON.parse(data.toString());
@@ -38,18 +39,22 @@ function greetPost(response, request){
postedNames.name.push(reqData.name);
console.log("Name sent from client and posted to postedNames object")
}else{
- reqData = "Not a string";
- resData = "You did not POST a string, try again!";
+ message = "Not a string";
console.log("Client tried to post a non-string");
}
- if(reqData === "Not a string"){
- response.write(resData);
+ if(message === "Not a string"){
console.log("Error written to response for bad POST from Client");
+ response.setHeader("Content-Type", "text/plain");
+ message.status(405);
+ response.write(message);
response.end();
console.log("Client sent error for bad POST from client");
}else{
console.log("Name written to stream");
+ response.setHeader("Content-Type", "text/plain");
+ message = "You have posted your name";
+ response.write(message);
response.end();
console.log("Name sent to client");
}
@@ -67,10 +72,8 @@ function serverTime(response){
var min = time.getMinutes();
var sec = time.getSeconds();
-
-
resData.status = 200;
- resData.contentType = "application/json";
+ response.setHeader("Content-Type", "text/plain");
response.write("The time in hour, minutes, seconds "+ hour + ":" + min + ":" + sec + ". For the miliseconds since 1970, you have " + Date.now());
console.log("Writing server time");
response.end();
diff --git a/dan_lombardy/test/server-test.js b/dan_lombardy/test/server-test.js
index 3eef1b0..4d5c654 100644
--- a/dan_lombardy/test/server-test.js
+++ b/dan_lombardy/test/server-test.js
@@ -5,40 +5,71 @@ var expect = chai.expect;
var chaiHttp = require('chai-http');
chai.use(chaiHttp);
var fs = require('fs');
+var router =require(__dirname + '/../lib/router');
+require(__dirname + '/../index');
-require(__dirname + '/../server');
-
-
+/*before('running', function(){
+ this.indexFileString = fs.readFileSync(__dirname + '/../public/index.html').toString();
+});
+*/
+describe('a server that returns the right routes', function(){
+ before(function() {
+ this.indexFileString = fs.readFileSync(__dirname + '/../public/index.html').toString();
+ });
+ it('a call to "/" should return an html page', function(done){
+ chai.request('localhost:3000')
+ .get('/')
+ .end(function(err, res){
+ expect(res).to.have.status(200);
+ expect(res).to.have.header('content-type');
+ expect(res).to.be.html;
+ expect(res.text).to.eql(this.indexFileString);
+ done();
+ }.bind(this));
+ });
+ it('a call to /greet will return plain text', function(done){
+ chai.request('localhost:3000')
+ .post('/greet')
+ .send({name: "spike"})
+ .end(function(err, res){
+ expect(res).to.have.status(200);
+ expect(res).to.have.header('content-type');
+ expect(res).to.be.text;
+ expect(res.text).to.eql("You have posted your name");
+ done();
+ }.bind(this));
+ });
+ it('a call to /greet/name will return plain text', function(done){
+ chai.request('localhost:3000')
+ .get('/greet/name')
+ .end(function(err, res){
+ expect(res).to.have.status(200);
+ expect(res).to.have.header('content-type');
+ expect(res).to.be.text;
+ expect(res.text.slice(0,5)).to.eql("hello");
+ done();
+ }.bind(this));
+ });
-/*
---take a request of any kind (router)
- --route that requst to the appropriate handler
- ---/timeout GET
- ---/greet/name GET
- --/greet POST
+ it('a call to /server will return plain text', function(done){
+ chai.request('localhost:3000')
+ .get('/server')
+ .end(function(err, res){
+ expect(res).to.have.status(200);
+ expect(res).to.have.header('content-type');
+ expect(res).to.be.text;
+ expect(res.text.slice(0,3)).to.eql("The");
+ done();
+ }.bind(this));
+ });
---do something with a request of any kind (requestHandler)
- route us to each file type that is returned due to the
- request (including the 404)
- --The server should respond to a request to /time that will send back the
- current time of the server.
- --It should also respond to a get request to /greet/name where name is
- any single word string. It should send back a string that greets that name.
- --It should also have a separate post request to /greet that takes the name in JSON format.
---entry point (index) to ignite process
---have an actual server tht runs (server.js).
- server takes in the request and response
-----There should be tests using chaiHTTP for both routes, as well as a gulpfile/package.json
---ou should have an html page that describes the routes implemented by the api available
- at the root of the server (for a bonus point auto populate the routes list, for another bonus point also style the html page)
-*/
-describe('')
+});