-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a40a49d
Showing
43 changed files
with
21,649 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "18" | ||
} | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
[ | ||
"module-resolver", | ||
{ | ||
"root": [ | ||
"./" | ||
], | ||
"alias": { | ||
"~": "." | ||
} | ||
} | ||
] | ||
], | ||
"env": { | ||
"development": { | ||
"sourceMaps": "inline", | ||
"retainLines": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
Dockerfile | ||
mock-api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"env": { | ||
"es2022": true, | ||
"node": true, | ||
"jest": true | ||
}, | ||
"extends": ["standard", "prettier"], | ||
"overrides": [], | ||
"parserOptions": { | ||
"ecmaVersion": "latest" | ||
}, | ||
"plugins": ["prettier"], | ||
"rules": { | ||
"prettier/prettier": "error", | ||
"no-console": "error" | ||
}, | ||
"ignorePatterns": [".server", "src/__fixtures__", "coverage"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Check Pull Request | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
types: | ||
- opened | ||
- edited | ||
- reopened | ||
- synchronize | ||
- ready_for_review | ||
|
||
jobs: | ||
pr-validator: | ||
name: Run Pull Request Checks | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
cache: npm | ||
- run: npm install | ||
- run: npm run format:check | ||
- run: npm run lint | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Publish | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
id-token: write | ||
contents: write | ||
pull-requests: write | ||
|
||
env: | ||
AWS_REGION: eu-west-2 | ||
AWS_ACCOUNT_ID: "094954420758" | ||
|
||
jobs: | ||
build: | ||
name: CDP-build-workflow | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build and Publish | ||
uses: defra-cdp-sandpit/cdp-build-action/build@main | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
.npm/ | ||
.vscode | ||
.idea | ||
.server | ||
node_modules | ||
npm-debug.log | ||
coverage | ||
.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npm test && npm run lint && npm run format:check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
save-exact=true | ||
git-tag-version=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v20.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.public | ||
.server | ||
package-lock.json | ||
node_modules | ||
coverage | ||
postman |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
tabWidth: 2, | ||
semi: false, | ||
singleQuote: true, | ||
trailingComma: 'none' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
ARG PARENT_VERSION=2.2.0-node20.3.0 | ||
ARG PORT=3000 | ||
ARG PORT_DEBUG=9229 | ||
|
||
FROM defradigital/node-development:${PARENT_VERSION} AS development | ||
ARG PARENT_VERSION | ||
LABEL uk.gov.defra.ffc.parent-image=defradigital/node-development:${PARENT_VERSION} | ||
|
||
ARG PORT | ||
ARG PORT_DEBUG | ||
ENV PORT ${PORT} | ||
EXPOSE ${PORT} ${PORT_DEBUG} | ||
|
||
COPY --chown=node:node package*.json ./ | ||
RUN npm install | ||
COPY --chown=node:node . . | ||
RUN npm run build | ||
|
||
CMD [ "npm", "run", "docker:dev" ] | ||
|
||
FROM defradigital/node:${PARENT_VERSION} AS production | ||
ARG PARENT_VERSION | ||
LABEL uk.gov.defra.ffc.parent-image=defradigital/node:${PARENT_VERSION} | ||
|
||
COPY --from=development /home/node/package*.json ./ | ||
COPY --from=development /home/node/.server ./.server/ | ||
|
||
RUN npm ci --omit=dev | ||
|
||
ARG PORT | ||
ENV PORT ${PORT} | ||
EXPOSE ${PORT} | ||
|
||
CMD [ "node", "./.server" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
The Open Government Licence (OGL) Version 3 | ||
|
||
Copyright (c) 2023 Defra | ||
|
||
This source code is licensed under the Open Government Licence v3.0. To view this | ||
licence, visit www.nationalarchives.gov.uk/doc/open-government-licence/version/3 | ||
or write to the Information Policy Team, The National Archives, Kew, Richmond, | ||
Surrey, TW9 4DU. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
# CDP Node Backend Template | ||
|
||
Core delivery platform Node.js Backend Template. | ||
|
||
- [Requirements](#requirements) | ||
- [Node.js](#nodejs) | ||
- [Local development](#local-development) | ||
- [Setup](#setup) | ||
- [Development](#development) | ||
- [Production](#production) | ||
- [Npm scripts](#npm-scripts) | ||
- [API endpoints](#api-endpoints) | ||
- [Calling API endpoints](#calling-api-endpoints) | ||
- [Postman](#postman) | ||
- [Versioning](#versioning) | ||
- [Auto minor versioning](#auto-minor-versioning) | ||
- [Major or Patch versioning](#major-or-patch-versioning) | ||
- [Docker](#docker) | ||
- [Development Image](#development-image) | ||
- [Production Image](#production-image) | ||
- [Licence](#licence) | ||
- [About the licence](#about-the-licence) | ||
|
||
## Requirements | ||
|
||
### Node.js | ||
|
||
Please install [Node.js](http://nodejs.org/) `>= v18` and [npm](https://nodejs.org/) `>= v9`. You will find it | ||
easier to use the Node Version Manager [nvm](https://github.com/creationix/nvm) | ||
|
||
To use the correct version of Node.js for this application, via nvm: | ||
|
||
```bash | ||
$ cd cdp-portal-stubs | ||
$ nvm use | ||
``` | ||
|
||
## Local development | ||
|
||
### Setup | ||
|
||
Install application dependencies: | ||
|
||
```bash | ||
$ npm install | ||
``` | ||
|
||
### Development | ||
|
||
To run the application in `development` mode run: | ||
|
||
```bash | ||
$ npm run dev | ||
``` | ||
|
||
### Production | ||
|
||
To mimic the application running in `production` mode locally run: | ||
|
||
```bash | ||
$ npm start | ||
``` | ||
|
||
### Npm scripts | ||
|
||
All available Npm scripts can be seen in [package.json](./package.json) | ||
To view them in your command line run: | ||
|
||
```bash | ||
$ npm run | ||
``` | ||
|
||
## API endpoints | ||
|
||
| Endpoint | Description | | ||
| :----------------------------- | :----------- | | ||
| `GET: /health` | Health | | ||
| `GET: /v1/entities` | Entities | | ||
| `GET: /v1/entities/<entityId>` | Entity by ID | | ||
|
||
## Calling API endpoints | ||
|
||
### Postman | ||
|
||
A [Postman](https://www.postman.com/) collection and environment are available for making calls to the Teams and | ||
Repositories API. Simply import the collection and environment into Postman. | ||
|
||
- [CDP Node Backend Template Postman Collection](postman/cdp-portal-stubs.postman_collection.json) | ||
- [CDP Node Backend Template Postman Environment](postman/cdp-portal-stubs.postman_environment.json) | ||
|
||
## Versioning | ||
|
||
### Auto minor versioning | ||
|
||
The [Publish GitHub Actions workflow](./.github/workflows/publish.yml) auto versions a Pull Requests code with a `minor` | ||
version once it has been merged into the `main` branch. | ||
All you have to do is commit your code and raise a Pull Request and the pipeline will auto version your code for you. | ||
|
||
### Major or Patch versioning | ||
|
||
If you wish to `patch` or `major` version your codebase use: | ||
|
||
```bash | ||
$ npm version <patch|major> | ||
``` | ||
|
||
Then: | ||
|
||
- Push this code with the auto generated commit to your GitHub Repository | ||
- Raise a Pull Request | ||
- Merge your code into the `main` branch | ||
- The [Publish GitHub Actions workflow](./.github/workflows/publish.yml) will tag and push your `major` or `patch` | ||
version tags to your GitHub Repository | ||
- The [Publish GitHub Actions workflow](./.github/workflows/publish.yml) will release your `major` or `patch` | ||
versioned code | ||
|
||
## Docker | ||
|
||
### Development image | ||
|
||
Build: | ||
|
||
```bash | ||
$ docker build --target development --no-cache --tag cdp-portal-stubs:development . | ||
``` | ||
|
||
Run: | ||
|
||
```bash | ||
$ docker run -e GITHUB_API_TOKEN -p 3008:3008 cdp-portal-stubs:development | ||
``` | ||
|
||
### Production image | ||
|
||
Build: | ||
|
||
```bash | ||
docker build --no-cache --tag cdp-portal-stubs . | ||
``` | ||
|
||
Run: | ||
|
||
```bash | ||
$ docker run -e GITHUB_API_TOKEN -p 3001:3001 cdp-portal-stubs | ||
``` | ||
|
||
## Licence | ||
|
||
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 license v3 | ||
### About the licence | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
rootDir: '.', | ||
testEnvironment: 'node', | ||
verbose: true, | ||
resetModules: true, | ||
clearMocks: true, | ||
silent: true, | ||
testMatch: ['**/src/**/*.test.js'], | ||
reporters: ['default', ['github-actions', { silent: false }], 'summary'], | ||
collectCoverageFrom: ['src/**/*.js'], | ||
coveragePathIgnorePatterns: [ | ||
'<rootDir>/node_modules/', | ||
'<rootDir>/.server', | ||
'<rootDir>/src/__fixtures__' | ||
], | ||
coverageDirectory: '<rootDir>/coverage' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2020", | ||
"baseUrl": "./", | ||
"paths": { | ||
"~/*": ["./*"] | ||
} | ||
}, | ||
"exclude": ["node_modules", "build"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"watch": [".public", "./src", "./mock-api"], | ||
"ignore": ["**/*.test.*", "./test-helpers", "./src/common/assets"], | ||
"ext": "js,json,njk,scss" | ||
} |
Oops, something went wrong.