Home Manual Reference Source Test API Healthcheck

Template Webpack REST Server

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

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

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

Development

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

  1. Download and update dependencies
  2. Update conf/config.yaml with any changes to settings
  3. Add new OpenAPI endpoint to ./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

Tests/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

TODO

Application

Issues

Issues seeing endpiont Error in Log:

Debug: handler, error
    Error: Not Found
    at internals.notFound

Occurs when you are using browser to hit endpoint that has not been registered with Server. Check:

Issues when properties missing/misnamed in controller route objects TODO: add issues

Issues when controllers/routes being duplicated TODO: add issues

Issues with wrong node version (<8) TODO: add issues

Issues when not using babel/polyfill

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: spawn mocha ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
    at onErrorNT (internal/child_process.js:362:16)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
    at process._tickCallback (internal/process/next_tick.js:181:9)
module.js:550
    throw err;
    ^

Error: Cannot find module 'babel-polyfill'