Closed zoe-1 closed 5 years ago
This is awesome! Are you looking for feedback, or is it feeling ready to you?
@devinivy Thanks for the input. I want to get this project back up to speed. But, lately been busy with a dive into cryptography.
No excuses run cleanup hapi extends
New assignment preparations below.
[Assignment1] Let's get started!
First, we need some basic structure: a lib folder, a package.json file, and an initial ./lib/index.js. Since we will be using hapi, we need to include that in the project dependencies.
Second, create a basic hapi server on port 8000 which responds to /version requests and replies with a simple
{ "version": "0.0.1" }
JSON payload. The version data in the response should come from the package.json file.Original Assignment1
Assignment1 solution
[Assignment2] Plugins
The right way to work with hapi is to build your application using plugins. Plugins provide a way to organize your code into logical components and then put them together in different combinations or deploy them in different configurations. While some plugins are published as general purpose utilities (e.g. adding authentication), you should think of plugins as a way to break your code into pieces.
Now that we have a basic server with one endpoint, we want to move the creation of the endpoint to a plugin, and then register that plugin with the server. Creating a new file
lib/version.js
and move the/version
endpoint there, wrapped in the pluginregister()
function.Then change our current
lib/index.js
to require the new file and register the version plugin with our server.Remember to follow the style guide, and ask any questions in the comments of the issue created for the assignment. If you are not sure how to get your fork back in sync with the current updated code, use the git guide.
Helps
require('./version') should be declared at the top and assigned to
Version`.{ register: Version }
. It is enough to just pass Version directly to theregister()
function.source for Helps: Discussion between @hueniverse and @TheAlphaNerd. Original Assignment2
Assignment2 Solution
[Assignment3] Testing & 100% coverage
Things are getting a bit more interesting...
It's time to add tests, verify coverage, confirm style, and automate all of this with CI. We will be using the lab module to perform all these tasks and automate it with travis.
.travis.yml
file. When a .travis.yml file exists in a GitHub repository the project is built and all tests are executed. .travis reports if all tests successfully passed or not.version.js
andindex.js
, each testing the corresponding file under/lib
.package.json
file to include the tests, as well as the dev dependency to lab.version.js
.init()
and move the invocation to a newstart.js
file (which will call the exportedinit()
function with the8000
port and a callback outputs the information to the console when started). Changepackage.json
file to use thestart.js
file as the starting place.start.js
file is not be covered by tests.Everything should be pretty straight forward. If you are not sure on how to use lab and code, look at other hapi.js modules and copy their test scripts and setup.
Getting 100% coverage can be tricky sometimes so if you are not sure, get as much coverage as you can, and comment on the lines in your pull request where you are having a hard time reaching and someone will give you a clue.
Remember to properly
stop()
your servers when calling theinit()
method in each test.For now, avoid using any of the
before()
andafter()
lab features.As always, ask for help and help others!
Helps
{ parallel: false }
lab option to make it both safe for future parallel testing as well as visual cue.Error
as an error (e.g. no strings, plain objects, etc.).0
or the default.return
beforenext()
unless there is a reason to continue.init()
required.server.inject()
with a GET request, just pass the path string as the first argument instead of an options object. Makes the code much more readable.Original assignment3 Assignment3 Solution
[Assignment4] Authentication
/version
.12345678
Original Assignment4 Assignment4 Solution
[Assignment5] TLS
Assignment5 Solution
[Assignment6] /authenticate & /private end points
./authenticate
and./private
points.{ debug: false }
config for tests. Otherwise, the tests print out hapi-auth-bearer-token error reports. Originally, added in assignment9 but can go here.Assignment6 Solution
[Assignment7] catabox-redis
Assignment7 Solution
[Assignment8] confidence
env
criteriaAssignment8 Solution
[Assignment9] good & lifecycle
good hapi process monitoring & extending hapi request lifecycle
good@8.0.0-rc1
before stable 8.1.1 released.npm i good@8.0.0-rc1
onPreResponse
step of the lifecycle for the ./private route. When invalid tokens are used to access ./private, log the event to logfile.{ debug: false }
config to Confidence file for tests. Otherwise, the tests print out hapi-auth-bearer-token error reports.Assignment9 Solution
[Assignment10] refactor
-[] determine if this is proper place to refactor. Or, rewrite previous assignments so no refactor is needed.
plugins
user
plugin.version
plugin and place inuser
. routeMethod cleanuptree after do refactor
Assignment10 Solution
[Assignment11] hapi & graphql (part1)
Assignment11 Solution
[Assignment12] hapi & graphql (part2)
Basic graph schema, queries and data source
Assignment12 Solution
[Assignment13] hapi & graphql (part3)
Assignment13 Solution
[Assignment14] hapi & graphql (part4)
flow added project
server.app.db
can be accessed by resolver functions.Assignment14 Solution
[Assignment15] hapi & graphql (part5)
Assignment15 Solution
[Assignment16] refactor
hapi
? Based upon talk I hear aboutgraphql
thought adding it to the project may attract more people.university-rewrite