Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.
/ ctsc-web-chat-sample Public archive
generated from hmcts/expressjs-template

A sample application for test ctsc-web-chat library

License

Notifications You must be signed in to change notification settings

hmcts/ctsc-web-chat-sample

Repository files navigation

Express application template

Greenkeeper badge

Build Status

Purpose

The purpose of this template is to speed up the creation of new Express frontend applications within HMCTS and help keep the same development standards across multiple teams. If you need to create a new application, you can simply use this one as a starting point and build on top of it.

What's inside

The template is a working application with a minimal setup. It contains:

  • application skeleton
  • common dependencies
  • Docker setup
  • static analysis set up
  • integration with Travis CI
  • HTTPS set up for development environment
  • CSRF prevention set up
  • Header-based security provided by Helmet
  • basic health endpoint
  • pa11y set up for accessibility testing
  • MIT license and contribution information

Getting Started

Prerequisites

Running the application requires the following tools to be installed in your environment:

Running the application

Install dependencies by executing the following command:

$ yarn install

Run:

$ gulp

The applications's home page will be available at https://localhost:3100

Running with Docker

Create docker image:

  docker-compose build

Run the application by executing the following command:

  docker-compose up

This will start the frontend container exposing the application's port (set to 3100 in this template app).

In order to test if the application is up, you can visit https://localhost:3100 in your browser. You should get a very basic home page (no styles, etc.).

Developing

Code style

We use ESLint alongside sass-lint

Running the linting:

$ yarn lint

Running the tests

This template app uses Mocha as the test engine. You can run unit tests by executing the following command:

$ yarn test

Here's how to run functional tests (the template contains just one sample test):

$ yarn test:routes

Running accessibility tests:

$ yarn test:a11y

Make sure all the paths in your application are covered by accessibility tests (see a11y.ts).

Security

CSRF prevention

Cross-Site Request Forgery prevention has already been set up in this template, at the application level. However, you need to make sure that CSRF token is present in every HTML form that requires it. For that purpose you can use the csrfProtection macro, included in this template app. Your njk file would look like this:

{% from "macros/csrf.njk" import csrfProtection %}
...
<form ...>
  ...
    {{ csrfProtection(csrfToken) }}
  ...
</form>
...

Helmet

This application uses Helmet, which adds various security-related HTTP headers to the responses. Apart from default Helmet functions, following headers are set:

There is a configuration section related with those headers, where you can specify:

  • referrerPolicy - value of the Referrer-Policy header
  • hpkp - settings for Public-Key-Pins header:

Here's an example setup:

    "security": {
      "referrerPolicy": "origin",
      "hpkp": {
        "maxAge": 2592000,
        "sha256s": [
          "M1J37nfPyNUdZgLkE3Iyz2BBqsK8Zjd344S5DVrnTVE=",
          "A1PTZTeHlA0idWnJThBl7rrbt1CoynD2vWcziKGDfkY="
        ]
      }
    }

Make sure you have those values set correctly for your application.

Healthcheck

The application exposes a health endpoint (https://localhost:3100/health), created with the use of Nodejs Healthcheck library. This endpoint is defined in health.ts file. Make sure you adjust it correctly in your application. In particular, remember to replace the sample check with checks specific to your frontend app, e.g. the ones verifying the state of each service it depends on.

License

This project is licensed under the MIT License - see the LICENSE file for details

About

A sample application for test ctsc-web-chat library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published