forked from outmoded/university
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assignment outmoded#1: Create a basic HTTP server.
- Loading branch information
1 parent
81a2158
commit 69731b4
Showing
5 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('./lib/index.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |