outmoded / university

Community learning experiment
Other
371 stars 194 forks source link

New Lessons and Solutions #259

Closed zoe-1 closed 5 years ago

zoe-1 commented 6 years ago

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 plugin register() 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

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.

  1. Add a .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.
  2. Add a test folder with two files, version.js and index.js, each testing the corresponding file under /lib.
  3. Modify the package.json file to include the tests, as well as the dev dependency to lab.
  4. When using lab, enable coverage, require 100% coverage, enable linting with default rules, and use the code assertion library.
  5. Write a basic test to verify our version endpoint in version.js.
  6. Export init() and move the invocation to a new start.js file (which will call the exported init() function with the 8000 port and a callback outputs the information to the console when started). Change package.json file to use the start.js file as the starting place. start.js file is not be covered by tests.
  7. Write a test to get 100% coverage.

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 the init() method in each test.

For now, avoid using any of the before() and after() lab features.

As always, ask for help and help others!

Helps

Original assignment3 Assignment3 Solution

[Assignment4] Authentication

Original Assignment4 Assignment4 Solution

[Assignment5] TLS

Assignment5 Solution

[Assignment6] /authenticate & /private end points

Assignment6 Solution

[Assignment7] catabox-redis

Assignment7 Solution

[Assignment8] confidence

Assignment8 Solution

[Assignment9] good & lifecycle

good hapi process monitoring & extending hapi request lifecycle

Assignment9 Solution

[Assignment10] refactor

-[] determine if this is proper place to refactor. Or, rewrite previous assignments so no refactor is needed.

plugins

tree after do refactor

lib/
├── authtoken.js
├── cache.js
├── certs
│   ├── cert.crt
│   └── key.key
├── config.js
├── database.js
├── index.js
├── routeMethod
│   ├── authenticate.js
│   ├── private.js
│   └── version.js
├── start.js
├── user.js
└── version.js

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)

Assignment14 Solution

[Assignment15] hapi & graphql (part5)

Assignment15 Solution

[Assignment16] refactor

university-rewrite

devinivy commented 6 years ago

This is awesome! Are you looking for feedback, or is it feeling ready to you?

zoe-1 commented 5 years ago

@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