Skip to content

Commit 1bf62b7

Browse files
authored
Merge pull request #165 from PublicHealthEngland/development
Essential updates and improvements No conflict detected.
2 parents bff1e14 + b226181 commit 1bf62b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1008
-5477
lines changed

.env.development

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
REACT_APP_BASE_URL=http://localhost:3000
2+
REACT_APP_MAIN_CDN=c19pubdev.azureedge.net
3+
REACT_APP_DOWNLOADS_CDN=c19downloadsdev.azureedge.net

.github/workflows/build_test.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,17 @@ jobs:
2929
run: |
3030
npm install
3131
yarn install
32-
32+
33+
# NOTE: Do NOT use trailing slashes in the URLs.
34+
# ATTENTION: `BASE_URL` must have the HTTP(S) protocol, but other URLs must not.
3335
- name: Build
3436
env:
3537
CI: false
36-
BASE_URL: https://coronavirus-staging.data.gov.uk/
38+
BUILD_ENV: development
39+
BASE_URL: https://covid19statdev.azureedge.net
40+
MAIN_CDN: c19pubdev.azureedge.net
41+
DOWNLOADS_CDN: c19downloadsdev.azureedge.net
42+
NODE_ENV: production
43+
3744
run: |
3845
npm run build
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build and deploy Node.js app to Azure Web App - Covid19StaticSTAGING
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
build-and-deploy:
10+
runs-on: windows-latest
11+
12+
steps:
13+
- uses: actions/checkout@master
14+
15+
- name: Set up Node.js version
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: '12.13.0'
19+
20+
- name: Install dependencies
21+
run: |
22+
npm install -g yarn
23+
npm install
24+
yarn install
25+
26+
# NOTE: Do NOT use trailing slashes in the URLs.
27+
# ATTENTION: `BASE_URL` must have the HTTP(S) protocol, but other URLs must not.
28+
- name: Build yarn
29+
env:
30+
CI: false
31+
BUILD_ENV: staging
32+
BASE_URL: https://Covid19StaticStaging.azureedge.net
33+
MAIN_CDN: c19pub.azureedgestaging.net
34+
DOWNLOADS_CDN: c19downloadsstaging.azureedge.net
35+
NODE_ENV: production
36+
37+
run: |
38+
yarn run build
39+
40+
- name: 'Deploy to Azure Web App'
41+
uses: azure/webapps-deploy@v1
42+
with:
43+
app-name: 'Covid19StaticSTAGING'
44+
slot-name: 'production'
45+
publish-profile: ${{ secrets.AzureAppServiceStaging }}
46+
package: ./build

.github/workflows/development_covid19-test-dashboard.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ jobs:
2525
npm install -g yarn
2626
npm install
2727
yarn install
28-
28+
29+
# NOTE: Do NOT use trailing slashes in the URLs.
30+
# ATTENTION: `BASE_URL` must have the HTTP(S) protocol, but other URLs must not.
2931
- name: Build yarn
3032
env:
3133
CI: false
34+
BUILD_ENV: development
35+
BASE_URL: https://covid19statdev.azureedge.net
36+
MAIN_CDN: c19pubdev.azureedge.net
37+
DOWNLOADS_CDN: c19downloadsdev.azureedge.net
38+
NODE_ENV: production
39+
3240
run: |
3341
yarn run build
3442

.github/workflows/master_covid19static.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ jobs:
2525
npm install -g yarn
2626
npm install
2727
yarn install
28-
28+
29+
# NOTE: Do NOT use trailing slashes in the URLs.
30+
# ATTENTION: `BASE_URL` must have the HTTP(S) protocol, but other URLs must not.
2931
- name: Build yarn
3032
env:
3133
CI: false
34+
BUILD_ENV: production
35+
BASE_URL: https://coronavirus.data.gov.uk
36+
MAIN_CDN: c19pub.azureedge.net
37+
DOWNLOADS_CDN: c19downloads.azureedge.net
38+
NODE_ENV: production
39+
3240
run: |
3341
yarn run build
3442

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55

66

7-
This is the source code for the [Coronavirus Dashboard](https://coronavirus.data.gov.uk) service.
7+
This is the main source code for the [Coronavirus Dashboard](https://coronavirus.data.gov.uk) service.
8+
9+
There are two additional repositories associated with this project:
10+
- The [Pipeline ETL repository](https://github.com/PublicHealthEngland/coronavirus-dashboard-pipeline-etl) for data transformation.
11+
- The [Terraform repository](https://github.com/PublicHealthEngland/coronavirus-dashboard-terraform) for building the test, staging and deployment environments.
812

913
## Development and contribution
1014

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "covid-public",
3-
"version": "1.6.0",
3+
"version": "1.6.1",
44
"private": true,
55
"homepage": "https://coronavirus.data.gov.uk/",
66
"dependencies": {
@@ -28,12 +28,13 @@
2828
"remark-toc": "^7.0.0",
2929
"remark-slug": "^6.0.0",
3030
"remark-html": "^11.0.1",
31-
"remark-external-links": "^6.0.0"
31+
"remark-external-links": "^6.0.0",
32+
"replacestream": "^4.0.3"
3233
},
3334
"scripts": {
3435
"lint": "yarn flow",
3536
"start": "react-scripts start",
36-
"build": "react-scripts build",
37+
"build": "react-scripts build && node scripts/patchUrls.js",
3738
"test": "react-scripts test",
3839
"eject": "react-scripts eject"
3940
},

public/index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
5+
<link rel="icon" href="%REACT_APP_BASE_URL%/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<meta name="theme-color" content="#000000" />
8+
<base href="%REACT_APP_BASE_URL%">
89
<meta
910
name="description"
1011
content="GOV.UK Coronavirus dashboard"
1112
/>
12-
<link rel="apple-touch-icon" href="%PUBLIC_URL%/favicon.png" />
13-
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
14-
<title>Coronavirus (COVID-19) cases in the UK</title>
13+
<link rel="apple-touch-icon" href="%REACT_APP_BASE_URL%/favicon.png" />
14+
<link rel="manifest" href="%REACT_APP_BASE_URL%/manifest.json" />
15+
<title>Coronavirus (COVID-19) in the UK</title>
1516
<!-- Google Analytics -->
1617
<script>
1718
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

scripts/patchUrls.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
"use strict";
2+
3+
const
4+
fs = require("fs"),
5+
path = require("path"),
6+
replaceStream = require("replacestream");
7+
8+
9+
/**
10+
* Default variables.
11+
*
12+
* .. note:: The behaviour of this function depends on two environment variables:
13+
* Either the `BUILD_ENV` should be set to one of `development`, `staging`
14+
* or `production`; or `NODE_ENV` must be set to `production`.
15+
*
16+
* .. note:: Do **NOT** use trailing slashes in the URL.
17+
*
18+
* .. attention:: `BASE_URL` must have the HTTP(S) protocol, but other URLs must not.
19+
*
20+
* @returns { {}|{DOWNLOADS_CDN: string, BASE_URL: string, MAIN_CDN: string} }
21+
*/
22+
const extractEnvVars = () => {
23+
24+
const prod = {
25+
BASE_URL: "https://coronavirus.data.gov.uk",
26+
MAIN_CDN: "c19pub.azureedge.net",
27+
DOWNLOADS_CDN: "c19downloads.azureedge.net"
28+
};
29+
30+
if ( process.env.NODE_ENV === "production" && !process.env.hasOwnProperty("BUILD_ENV"))
31+
return prod;
32+
33+
34+
switch (process.env.BUILD_ENV) {
35+
case "development":
36+
return {
37+
BASE_URL: "https://covid19statdev.azureedge.net",
38+
MAIN_CDN: "c19pub.azureedgedev.net",
39+
DOWNLOADS_CDN: "c19downloadsdev.azureedge.net"
40+
}
41+
42+
case "staging":
43+
return {
44+
BASE_URL: "https://Covid19StaticStaging.azureedge.net",
45+
MAIN_CDN: "c19pub.azureedgestaging.net",
46+
DOWNLOADS_CDN: "c19downloadsstaging.azureedge.net"
47+
}
48+
49+
case "production":
50+
return prod
51+
52+
default:
53+
return {}
54+
55+
}
56+
57+
}; // extractEnvVars
58+
59+
60+
/**
61+
* Extracts ".js" and ".html" files in `directory` and its subdirectories
62+
* and returns an array of absolute paths.
63+
*
64+
* @param directory { string }
65+
* @returns { string[] }
66+
*/
67+
const getFiles = (directory) => {
68+
69+
return fs
70+
.readdirSync(directory, { withFileTypes: true })
71+
.reduce((acc, item) => [
72+
...acc,
73+
...item.isDirectory()
74+
? getFiles(path.join(directory, item.name))
75+
: [ path.join(directory, item.name) ]
76+
], [])
77+
.filter(file => /\.(js|html)$/i.exec(file))
78+
79+
}; // getFiles
80+
81+
82+
/**
83+
* Replaces placeholders formatted as `%key%` with environment
84+
* variables defined using the same key.
85+
*
86+
* @returns { Promise<void> }
87+
*/
88+
const main = async () => {
89+
90+
const
91+
directory = path.join(__dirname, "..", "build"),
92+
files = getFiles(directory),
93+
Replacements = {
94+
...extractEnvVars(),
95+
...process.env
96+
};
97+
98+
for ( const file of files ) {
99+
100+
const tmpFile = `${ file }.tmp`;
101+
102+
await new Promise((resolve, reject) => {
103+
const stream = Object
104+
.keys(Replacements)
105+
.reduce((stream, key) =>
106+
stream
107+
.pipe(replaceStream(`%${ key }%`, Replacements[key]))
108+
.pipe(replaceStream(`%REACT_APP_${ key }%`, Replacements[key])),
109+
fs.createReadStream(file)
110+
)
111+
.pipe(fs.createWriteStream(tmpFile));
112+
113+
stream.on("finish", resolve);
114+
stream.on("error", reject);
115+
});
116+
117+
fs.unlinkSync(file);
118+
fs.copyFileSync(tmpFile, file);
119+
fs.unlinkSync(tmpFile);
120+
121+
}
122+
123+
}; // main
124+
125+
126+
main().catch(err => {
127+
console.error(err);
128+
process.exitCode = 1;
129+
});

src/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const App = () => {
7777
{/* These back-to-top links are the 'overlay' style that stays
7878
on screen as we scroll. */}
7979
<Route path="/about" exact render={ () => <BackToTop mode={ "overlay" }/> } />
80+
<Route path="/accessibility" exact render={ () => <BackToTop mode={ "overlay" }/> } />
8081
<Route path="/" exact render={ () => <BackToTop mode={ "overlay" }/> } />
8182
</Switch>
8283

0 commit comments

Comments
 (0)