Skip to content
This repository was archived by the owner on Apr 8, 2019. It is now read-only.

Assignment #1 #36

Closed
wants to merge 4 commits into from
Closed
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
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.idea
*.iml
npm-debug.log
dump.rdb
node_modules
results.tap
results.xml
config.json
.DS_Store
*/.DS_Store
*/*/.DS_Store
._*
*/._*
*/*/._*
coverage.*
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib');
Copy link
Contributor

Choose a reason for hiding this comment

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

no reason to export here, made the same "mistake" ;)

32 changes: 32 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';
var Hapi = require('hapi');
var Hoek = require('hoek');

var internals = {
pack: require('../package.json')
};

var server = module.exports = new Hapi.Server();

server.connection({
port: 8000
});

server.route([{
method: 'GET',
path: '/version',
config: {
description: 'version from package.json',
handler: function(request, reply) {

return reply({ version: internals.pack.version })
.type('application/json');

Choose a reason for hiding this comment

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

No need to specify type manually. hapi will automatically set it.

}
}
}]);

server.start(function(err) {

Hoek.assert(!err, err);
return console.log('Server started at', server.info.uri);
});
115 changes: 115 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"name": "hueniversity",
"version": "0.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

should be 0.0.1

"description": "This is a community learning experiment. The idea is simple - use GitHub as a platform for teaching people coding skills as a group, where everyone is both a student and a teacher. The goal is to learn how to operate such a distributed classroom and then apply that pattern to other topics by other people.",
"main": "index.js",
"scripts": {
"start": "node .",
"watch": "pm2 start index.js --watch --name hueniversity",
"stop": "pm2 stop --watch hueniversity",
"test": "lab -t 100 -L",
"test-cov-html": "lab -r html -o coverage.html"
},
"repository": {
"type": "git",
"url": "https://github.com/MrBri/hueniversity.git"
Copy link
Contributor

Choose a reason for hiding this comment

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

should point to upstream (hueniverse)

},
"author": "Tyler Briles",
"license": "BSD",
"bugs": {
"url": "https://github.com/hueniverse/hueniversity.git"
},
"homepage": "https://github.com/hueniverse/hueniversity",
"dependencies": {
"hapi": "^8.4.0",
"hoek": "^2.11.1"
},
"devDependencies": {
"code": "^1.3.0",
"lab": "^5.5.0",
"pm2": "^0.12.7"
},
"eslintConfig": {

Choose a reason for hiding this comment

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

If you really want to specify lint rules, use an rc file instead of putting it in package.json. Cleaner.

"rules": {
"consistent-return": 0,
"vars-on-top": 0,
"one-var": 0,
"strict": 0,
"new-cap": 0,
"no-console": 0,
"no-constant-condition": 0,
"no-empty": 0,
"no-native-reassign": 0,
"no-underscore-dangle": 0,
"no-undef": 0,
"no-process-exit": 0,
"no-unused-vars": 0,
"no-use-before-define": 0,
"no-unused-expressions": 0,
"no-regex-spaces": 0,
"no-shadow": 0,
"global-strict": 0,
"handle-callback-err": 0,
"no-lonely-if": 0,
"space-in-brackets": 0,
"brace-style": 0,
"dot-notation": 1,
"eol-last": 1,
"camelcase": 1,
"no-trailing-spaces": 1,
"no-eq-null": 1,
"no-extend-native": 1,
"no-redeclare": 1,
"no-loop-func": 1,
"yoda": [
1,
"never"
],
"sort-vars": 1,
"quotes": [
2,
"single"
],
"consistent-this": [
2,
"self"
],
"func-style": [
2,
"expression"
],
"new-parens": 2,
"no-array-constructor": 2,
"no-new-object": 2,
"no-spaced-func": 2,
"no-space-before-semi": 2,
"no-mixed-spaces-and-tabs": 2,
"space-after-keywords": 2,
"semi": [
2,
"always"
],
"space-infix-ops": 2,
"space-return-throw-case": 2,
"space-unary-ops": [
1,
{
"words": true,
"nonwords": false
}
],
"eqeqeq": 2,
"curly": [
2,
"all"
],
"no-eval": 2,
"no-else-return": 2,
"no-return-assign": 2,
"no-new-wrappers": 2,
"no-comma-dangle": 2,
"no-sparse-arrays": 2,
"no-ex-assign": 2
}
}
}
27 changes: 27 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
var Code = require('code');
var Lab = require('lab');

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 return a version', function(done) {

var server = require('../lib/index');

Choose a reason for hiding this comment

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

This is fine for now but will become a problem since the test has little control over the creation of the server.

Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't that be covered by Lab?

Choose a reason for hiding this comment

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

Well, it will be handled when we restructure this app in the next assignment...


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

expect(res.statusCode).to.equal(200);
expect(server.info.port).to.equal(8000);
expect(res.payload).to.equal('{"version":"0.0.1"}');
done();
});
});

});