Code Monkey home page Code Monkey logo

template.hapi.rest's Introduction

version
0.7.0-SNAPSHOT

Template Webpack REST Server

GitHub License FOSSA Status
GitHub last commit GitHub Workflow Status
Dependency Check by David Dev Dependency Check by David
ESDoc Status CII Best Practices Summary OpenAPI/Swagger Validator
GitHub issues GitHub issues by-label

Intro

Template and Example using Webpack for rapid development of an REST API server with endpoints for managing requests and connections to other servers and/or database/storage tools.

This example can also be used to quickly create a server with your own endpoints to do whatever you would like on any requests (either user/interaction based, or with a cron job to make it on a scheduled basis)

Dependencies/Frameworks

Node v10+ and npm (tested with v10.15.1)

See package.json(github) for full list of current dependencies

  • Hapi v18 -- Server Library
  • Webpack + Loaders -- managing the build process
  • Babel -- compiling newer ECMA2016+ into browser-capable javascript
  • FlowJS -- adding types to javascript
  • ESLint -- enforcing javascript code style
  • Mocha, Chai, and Sinon -- unit testing
  • EsDoc -- creating easy javascript documentation
  • MariaDB -- Connecting to mysql/mariadb server for storage
  • YamlJS -- Parsing YAML files

Quick Setup/Run

How to use this template to create a quick HTTP REST server:

  1. Download and update node + dependencies
  2. Update conf/config.yaml with any changes to settings
  3. Add endpoint definitions to OpenAPI config in ./openapi.yaml
  4. Add Unit tests in src/controllers/ (Test Driven Development)
  5. Add Controller Files to src/controllers/
    • For now, add reference to controller in src/entry.js (with other controllers)
    • Controller endpoints will be served at /api (or whatever is set in config.yaml)
  6. Run npm run doc to update the documentation
  7. Run npm run start-watch to compile and run server + tests in watch mode

NPM Commands for Testing/Running

npm run start-watch to run open the server and run Webpack to watch for changes, recompiling, running the tests and restarting the server when it is done

npm run test-watch to run Mocha and with all tests associated with the project, watch for changes on the files to re-run the tests

npm run dev-watch to run only webpack to watch for changes on the files and recompile/rerun tests

npm run test to run all of the unit tests for the application one time

npm run dev to run a development version of the server

npm run build to compile development version of server to dist/

npm run doc to generate static documentation in the doc folder

npm run lint to run linter and see any errors/warnings

npm run clean clean the workspace (remove dist/)

npm run help to print the contents of help.txt to the command line

TODO

npm run build-prod ... TODO: compile application to production version

npm start .. TODO: start production Server

npm stop .. TODO: stop production Server

npm restart will restart once start/stop completed

Links

Contributors

template.hapi.rest's People

Contributors

dependabot[bot] avatar devlinjunker avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

fossabot

template.hapi.rest's Issues

Semantic Versioning

Figure out how to do semantic versioning

Ideas:

Contract testing

Tests for external APIs we use to verify they still behave how expected

Setup/Database Init

  • check nvm installed and node correct version
  • require node 10+
  • npm install?
  • db sql scripts/setup?
  • sequelize?

Add Badges to README


Other README stuff:

  • add link to wiki in README
  • Also cleanup todos to other file (notes.md - eventually move all to github issues)
  • add gif of command line install/startup and server response

Config Helper Class with `env.properties` config file

setup config helper class to read from config.yaml (and env.properties?)

  • config.yaml contains the structure of configuration and default values
  • env.properties file should just be format <name>=<value> for parsing and setting values in config.yaml
  • think about simple replacement in these name value pairs so we can have "variables" in config file
e.g. 
var=1
host=domain-name-${var}.com

RESULT host=domain-nomain-1.com

Upgrade webpack version

Describe the Improvement:
Use webpack 4+ and updated plugins

Steps:

  1. Update plugins
  2. Update webpack

Additional Context and Links:
N/A

Testing:
Server still builds and runs after upgrade

MongoDB Helper

Next:

  • Simple endpoints for rapid development and storage of JSON objects created in the UI components while doing UI development
  • CrudDataservice class that can be extended
    • defines name and properties (JOI validation?)
    • create/read/readAll/update/delete methods that can be overwritten and called in child classes

Explore Github Actions

https://github.com/devlinjunker/template.node.hapi/actions/new

First:

On PR:

  • Create dependency graph of files modified and comment on PR
  • Check if READMEs exist at each directory level?
  • Check if spec files exist (except where special comment in file header)
  • Pull request labeler based on the branch name
  • Lint PR Body/Name
  • Provide Label Assistance?
  • CRAZY: Deploy to test/demo server and add link to PR (via comment)
  • ERROR on console logs or unfinished tests (in release?)
    • create npm run merge-lint in package.json
    • adds rule errors via command line flags: ./node_modules/.bin/eslint src/ --rule 'no-console: error' --rule 'mocha/no-pending-tests: error'
    • NEED to remove console log and finish tests before this

On Merge to master:

Other:

Notes
https://help.github.com/en/actions/reference/events-that-trigger-workflows

  • IDEA: github action to sync todos.md file with github issues
    • whenever line with checkbox added, create issue and append number
    • when checked in file and committed, close issue
    • when issue created, add name and number to file
    • when issue closed, check in file

Passing Core Initiative Ranking

Describe the change:
There are a couple of sections in the Core Initiative checklist that seem valuable to include in documentation

  • Semantic versioning (#13)
  • Release Notes
  • Vulnerability report response (14 days - last 6 months)
  • Tests coverage percentage (80% branches? 90% lines)
  • Tests for all feature policy (add formally)
  • Warning flags (< 1/100 lines of code)
  • Security Notes to SECURITY.md:
    • economy of mechanism (keep the design as simple and small as practical, e.g., by adopting sweeping simplifications)
    • fail-safe defaults (access decisions should deny by default, and projects' installation should be secure by default)
    • complete mediation (every access that might be limited must be checked for authority and be non-bypassable)
    • open design (security mechanisms should not depend on attacker ignorance of its design, but instead on more easily protected and changed information like keys and passwords)
    • separation of privilege (ideally, access to important objects should depend on more than one condition, so that defeating one protection system won't enable complete access. E.G., multi-factor authentication, such as requiring both a password and a hardware token, is stronger than single-factor authentication)
    • least privilege (processes should operate with the least privilege necessary)
    • least common mechanism (the design should minimize the mechanisms common to more than one user and depended on by all users, e.g., directories for temporary files)
    • psychological acceptability (the human interface must be designed for ease of use - designing for "least astonishment" can help)
    • limited attack surface (the attack surface - the set of the different points where an attacker can try to enter or extract data - should be limited)
    • input validation with allowlists (inputs should typically be checked to determine if they are valid before they are accepted; this validation should use allowlists (which only accept known-good values), not denylists (which attempt to list known-bad values)).
  • Dynamic code analysis

Additional context/Links:
https://bestpractices.coreinfrastructure.org/en/projects/4288/

Related
#29
#13

Add Github Expected docs to Repo

Files to explain how to contribute to the repo and more

https://github.com/devlinjunker/template.hapi.rest/community

Fix Github Security Alerts

  • Update dependencies defined in Security tab
  • Run npm update in project and save package (maybe fix that caniuse-lite is outdated error)

Websocket Endpoint for Log File

Spinoff from #4 so we have a new task to track this idea

  • /admin/logs websocket endpoint that shows logfile
  • Prettier version linked at /docs/logs
    • filtering/searching
  • think about securing behind password/secret kept in config?

Githook improvements

Production Build and Config

Add Build job and Configuration for Production Code Generation

  • Webpack config
  • Minimization? Probably not on API
  • No Linter Warnings allowed?
  • No output/uncaught exceptions in tests?
  • pm2 for production
  • config file/env.properties
  • log rotation
  • Uncaught exceptions in production build send message
    • slack?
    • email?
    • text?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.