Giter Club home page Giter Club logo

defra.ivory's Introduction

Ivory Project

Digital service to support the Ivory Act.

Environment variables

The default values will be used if the environment variables are missing or commented out.

name description required default valid notes
NODE_ENV Node environment no development,test,production
PORT Port number no 3000
SERVICE_NAME Name of the service no Any text string
COOKIE_VALIDATION_PASSWORD Cookie encoding password yes Any text string
REDIS_HOST Redis server IP address no 127.0.0.1
REDIS_PORT Redis port number no 6379
SERVICE_API_ENABLED Enable/disable ivory API yes false true,false
SERVICE_API_HOST Ivory API IP address no 127.0.0.1
SERVICE_API_PORT Ivory API port number no 3010

Prerequisites

Node v14.x

Redis

Running the application

First install the dependencies & build the application using:

$ npm install

Currently this will just build the govuk-frontend sass and create a default .env file if one doesn't already exist. But may be extended to include other build tasks as needed (e.g. client-side js using browserify or webpack etc.)

If installing on a Windows machine you may encounter an error when running $ npm install relating to your OS not being able to run the Bash scripts which are part of the installation. Should you have this problem first ensure that you have installed Git for Windows. Then run the command $ npm config set script-shell %userprofile%\cmder\vendor\git-for-windows\bin\bash followed by $ npm install.

Now the application is ready to run:

$ npm start or $ node index.js

To run the application in Docker

$ npm run docker or $ npm run docker:build followed by $ npm run docker:run

Project structure

Here's the default structure for your project files.

  • bin (build tasks)
  • client (client js/sass code)
  • server
    • plugins
    • public (This folder is publicly served)
      • static (Put all static assets in here)
      • build (This contains the build output files (js/css etc.) and is not checked-in)
    • routes
    • services
    • views
    • config.js
    • index.js (Exports a function that creates a server)
  • test
  • README.md
  • index.js (startup server)

Config

The configuration file for the server is found at server/config.js. This is where to put any config and all config should be read from the environment. The final config object should be validated using joi and the application should not start otherwise.

A table of environment variables should be maintained in this README.

Plugins

hapi has a powerful plugin system and all server code should be loaded in a plugin.

Plugins live in the server/plugins directory.

Logging

The good and good-console plugins are included and configured in server/plugins/logging

The logging plugin is only registered in when NODE_ENV=development.

Error logging for production should use errbit.

Views

The vison plugin is used for template rendering support.

The template engine used in nunjucks inline with the GDS Design System with support for view caching, layouts, partials and helpers.

Static files

The Inert plugin is used for static file and directory handling in hapi.js. Put all static assets in server/public/static.

Any build output should write to server/public/build. This path is in the .gitignore and is therefore not checked into source control.

Routes

Incoming requests are handled by the server via routes. Each route describes an HTTP endpoint with a path, method, and other properties.

Routes are found in the server/routes directory and loaded using the server/plugins/router.js plugin.

Hapi supports registering routes individually or in a batch. Each route file can therefore export a single route object or an array of route objects.

A single route looks like this:

{
  method: 'GET',
  path: '/hello-world',
  options: {
    handler: (request, h) => {
      return 'hello world'
    }
  }
}

There are lots of route options, here's the documentation on hapi routes

Tasks

Build tasks are created using simple shell scripts or node.js programs. The default ones are found in the bin directory.

The task runner is simply npm using npm-scripts.

The predefined tasks are:

  • npm start (Runs the application)
  • npm run build (Runs all build sub-tasks)
  • npm run build:css (Builds the client-side sass)
  • npm run docker (Runs all Docker sub-tasks)
  • npm run docker:build (Builds the application in a Docker container)
  • npm run docker:run (Runs the application in the Docker container)
  • npm run lint (Runs the lint task using standard.js)
  • npm run unit-test (Runs the lab tests in the /test folder)
  • npm test (Runs the lint task then the unit-tests)

Testing

lab and code are used for unit testing.

See the /test folder for more information.

Linting

standard.js is used to lint both the server-side and client-side javascript code.

It's defined as a build task and can be run using npm run lint.

defra.ivory's People

Contributors

surgisonb avatar ajaxscape avatar jozzey avatar dgretho avatar duncannixon avatar davidharriswork avatar

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.