Skip to content

Commit

Permalink
Assignment outmoded#1: Create a basic HTTP server.
Browse files Browse the repository at this point in the history
  • Loading branch information
shanewwarren committed Jun 23, 2015
1 parent 81a2158 commit 69731b4
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.idea
*.iml
npm-debug.log
dump.rdb
node_modules
results.tap
results.xml
config.json
.DS_Store
*/.DS_Store
*/*/.DS_Store
._*
*/._*
*/*/._*
coverage.*
.settings
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./lib/index.js');
36 changes: 36 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var Hapi = require('hapi');
var Hoek = require('hoek');

var package = require('../package.json');


var internals = {
description: package.description,
staticVersion: {
version: package.version
}
};

// Create a server with a host and port
var server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 8080
});


// Add the route
server.route({
method: 'GET',
path: '/version',
handler: function (request, reply) {
return reply(internals.staticVersion);
}
});

server.start(function (error) {
Hoek.assert(!error, error);
console.log(internals.description, server.info.uri);
});

module.exports = server;
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "hapi-university-assignment-one",
"version": "0.0.1",
"description": "Create a basic HTTP Hapi server. ",
"main": "index.js",
"scripts": {
"test": "lab tests/test.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/hapijs/university.git"
},
"keywords": [
"hapi",
"http",
"server"
],
"author": "Shane Warren",
"license": "BSD-2-Clause",
"bugs": {
"url": "https://github.com/hapijs/university/issues"
},
"homepage": "https://github.com/hapijs/university#readme",
"dependencies": {
"hapi": "^8.6.1"
},
"devDependencies": {
"code": "^1.4.1",
"hoek": "^2.14.0",
"lab": "^5.11.0"
}
}
25 changes: 25 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var Code = require('code');
var Lab = require('lab');
var server = require('../lib/index.js');

var lab = exports.lab = Lab.script();

var describe = lab.describe;
var it = lab.it;
var before = lab.before;
var after = lab.after;
var expect = Code.expect;


describe('Server', function () {

it('should get the api version', function (done) {

server.inject('/version', function(response) {

expect(response.statusCode).to.equal(200);
expect(response.result.version).to.equal('0.0.1');
done();
});
});
});

0 comments on commit 69731b4

Please sign in to comment.