The Core Delivery Platform (CDP), Portal Frontend is a web application that provides a user interface for CDP.
Please install Node.js >= v20
and npm >= v9
.
Tip
To install Node.js and npm Use Node Version Manager nvm
To use the correct version of Node.js for this application, via nvm:
cd cdp-portal-frontend
nvm use
Install application dependencies:
npm install
The Portal Frontend has a number of APIs it uses to perform actions on the Platform and APIs to obtain information about the Platform and its tenants.
The Portal Frontend uses Redis for session storage. When the application is run on AWS it does so on a Redis/ElastiCache Cluster, locally it uses 1 Redis instance. To set up Redis locally, refer to the documentation found:
Run the application in development
mode run:
npm run dev
To update dependencies, globally install https://www.npmjs.com/package/npm-check-updates. Then run the below script,
run tests, test the application and commit the altered package.json
and package-lock.json
files. For more
options around updates check the package docs.
ncu -i
To set up Node.js
debugging in your IDE:
To run debug mode:
npm run dev:debug
To run all tests with coverage:
npm test
Tip
Or use the shortcut:
npm t
To run a specific test:
npm test -i <test-path>
E.g:
npm test -i src/server/health/controller.test.js
To see if your nock
mocks are matching your tests calls set the following environment variable in your test
environment:
export DEBUG=nock.*
For more information see https://github.com/nock/nock#debugging
To run code linting:
npm run lint
To run code lint for JavaScript:
npm run lint:js
To run an automatic code fix for JavaScript:
Note this is pretty good but may also need some manual human interaction
npm run lint:fix
To run code lint for SASS:
npm run lint:scss
This code base uses Prettier to keep code formatted in a uniform way. When you first clone the repository set up Prettier to run on save in your IDE.
To check formatting changes:
npm run format:check
To format code:
npm run format
You can see examples of the icons used throughout the application in src/server/common/components/icons. To create icons:
- Copy and rename an existing component from src/server/common/components/icons
- Choose an icon from Material Symbols
- The icons used already are:
- Fill ✅
- Weight
700
- Grade
200
- Size
48px
- Download the SVG file
- Go to svgomg
- Upload the SVG file
- Click Markup tab
- Copy markup and place it into an icon component
- Update CSS class names, macro name etc, to the new icons name
- Import the icon into your page, or if used globally in multiple places into src/server/common/templates/layouts/page.njk
To mimic the application running in production
mode locally run:
npm start
All available Npm scripts can be seen in package.json To view them in your command line run:
npm run
Build:
docker build --target development --no-cache --tag cdp-portal-frontend:development .
Run:
docker run -p 3000:3000 cdp-portal-frontend:development
Build:
docker build --no-cache --tag cdp-portal-frontend .
Run:
docker run -p 3000:3000 cdp-portal-frontend
A few examples of how to use LocalStack with the Portal Frontend.
To generate test reports and upload them to S3 to be displayed locally in the Portal Frontend UI:
## Start localstack
docker run --pull=always -d -p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack:latest
## Create S3 bucket
awslocal s3 mb s3://cdp-<environment>-test-results --endpoint-url http://localhost:4566
### fEx:
awslocal s3 mb s3://cdp-dev-test-results --endpoint-url http://localhost:4566
## Run tests
### Smoke tests
cd cdp-portal-smoke-tests
npm run report
### Perf tests
cd cdp-uploader-perf-tests
jmeter -n -t scenarios/test.jmx -e -l test.csv -o reports -j logs/log.log -f -Jenv="perf-test"
## Upload test results to S3
awslocal s3 cp <local-folder-name> s3://<s3-bucket-name/local-folder-name/> --recursive
### fEx:
awslocal s3 cp reports s3://cdp-infra-dev-test-results/cdp-portal-perf-tests/95a01432-8f47-40d2-8233-76514da2236a --recursive
awslocal s3 cp allure-report s3://cdp-infra-dev-test-results/cdp-portal-smoke-tests/5002a961-e6dd-4e7b-a544-a55c907b6b9f --recursive
To upload documentation repository to localstack S3 so it displays locally in the Portal Frontend UI:
## Start localstack
docker run --pull=always -d -p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack:latest
## Create S3 bucket
awslocal s3 mb s3://cdp-documentation --endpoint-url http://localhost:4566
## Upload docs to localstack S3
git clone https://github.com/DEFRA/cdp-documentation/
cd cdp-documentation
awslocal s3 sync . s3://cdp-documentation --exclude ".editorconfig" --exclude ".github/*" --exclude ".git/*" --exclude ".gitignore" --exclude "CONTRIBUTING.md" --delete
To set up the web shell so it displays locally in the Portal Frontend UI:
- Web Shell Proxy - https://github.com/DEFRA/cdp-webshell-proxy
- Web Shell - https://github.com/christopherjturner/webshell
cd cdp-webshell-proxy
pip3 install -r requirements.txt
pip3 install "fastapi[standard]"
## Start proxy
fast api dev app.py
## Register a route
curl --header "Content-type: application/json" --data-raw '{"id":"12345","target":"localhost"}' 'http://localhost:8080/admin/register'
## Start the web shell
git clone https://github.com/christopherjturner/webshell
install go https://go.dev/doc/install
go run . -port 8085 -token 12345
## Open the web shell
http://localhost:8000/12345/
## De-register a route
curl http://localhost:8080/admin/deregister/12345'
THIS INFORMATION IS LICENSED UNDER THE CONDITIONS OF THE OPEN GOVERNMENT LICENCE found at:
http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3
The following attribution statement MUST be cited in your products and applications when using this information.
Contains public sector information licensed under the Open Government licence v3
The Open Government Licence (OGL) was developed by the Controller of Her Majesty's Stationery Office (HMSO) to enable information providers in the public sector to license the use and re-use of their information under a common open licence.
It is designed to encourage use and re-use of information freely and flexibly, with only a few conditions.