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
2 changes: 2 additions & 0 deletions Iryna_Bondarenko/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

node_modules
29 changes: 29 additions & 0 deletions Iryna_Bondarenko/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var appFiles = ['index.js', '/*.js', 'bin/**/*.js'];
var testFiles = ['./Iryna_Bondarenko/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('jshint', ['jshint:test', 'jshint:app']);
gulp.task('default', ['jshint']);
26 changes: 26 additions & 0 deletions Iryna_Bondarenko/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "http_server",
"version": "1.0.0",
"description": "creating http server with routes",
"main": "server.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"keywords": [
"http",
"server"
],
"author": "irusiabondarenko@gmail.com",
"license": "ISC",
"devDependencies": {
"chai": "^3.4.0",
"chai-http": "^1.0.0",
"gulp": "^3.9.0",
"gulp-jshint": "^1.12.0",
"mocha": "^2.3.3"
}
}
15 changes: 15 additions & 0 deletions Iryna_Bondarenko/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are tabbed out a bit too far

<title>Greet website</title>
</head>
<body>
<h2>1 route: /time</h2>
<h3> This route says the local time in Seattle</h3>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make these <h3> tags into <p> tags - when you make everything "important", it just means nothing stands out as important anymore.

<h2>2 route: /greet/name </h2>
<h3> Returns a greet string which takes the name parameter for greeting <h3>
<h2> 3 route : /greet/name (Post request) </h2>
<h3> Returns JSON string {hello: 'some_name'}. I'm checking it via superagent in command line. </h3>
</body>
</html>
42 changes: 42 additions & 0 deletions Iryna_Bondarenko/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var http = require('http');
var fs = require('fs');
var url = require('url') ;
var ReadStream = require('stream').Readable;

var server = http.createServer(function(req, res) {
var resData= {};
if (req.url === '/time' && req.method === 'GET') {
resData.status = 200;
resData.contentType = 'text/html';
resData.data = "Local time in Seattle is " + time;
}

var url = req.url;
var str_url = url.slice(0,7);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare all your variables together at the top of your function or file

var name = url.slice(7);

if (str_url === '/greet/' && req.method === 'GET') {
this.name = name;
resData.status = 200;
resData.contentType = 'text/html';
resData.data = "Hello " + this.name + "! Have a nice day!"
}
if (str_url === '/greet/' && req.method === 'POST') {
resData.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');
});

var date = new Date ();
var time = date.toLocaleTimeString();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful styling on this code! :)

39 changes: 39 additions & 0 deletions Iryna_Bondarenko/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';
var chai = require('chai');
var expect = chai.expect;
var chaihttp = require('chai-http');
chai.use(chaihttp);

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

describe('our server', function(){
it('should get the time', function(done){
chai.request('localhost:3000')
.get('/time')
.end(function(err, res){
expect(err).to.eql(null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are tabbed in too far - they just need to be indented once from the .end() on line 13

expect(res).to.have.status(200);
done();
});
});

it('should get the name as parameter and greet the name', function(done){
chai.request('localhost:3000')
.get('/greet/name')
.end(function(err, res){
expect(err).to.eql(null);
expect(res).to.have.status(200);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

done();
});
});

it("should post JSON string with some name", function(done){
chai.request('localhost:3000')
.post('/greet/name')
.end(function(err, res){
expect(err).to.eql(null);
expect(res).to.have.status(200);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

done();
});
});
});