Skip to content

Commit

Permalink
Merge pull request #43 from diggsweden/3.1.4
Browse files Browse the repository at this point in the history
3.1.4
  • Loading branch information
dajjen authored Sep 26, 2023
2 parents 5716148 + b705b5f commit bb2765e
Show file tree
Hide file tree
Showing 25 changed files with 107 additions and 97 deletions.
8 changes: 0 additions & 8 deletions .env.development

This file was deleted.

24 changes: 24 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
PORT=3000
HOST=http://localhost:$PORT
REACT_APP_RUNTIME_ENV=dev

LOGFILE_PATH=dataportal.log
LOGGING_LEVELS=warn,error,info
HEALTHCHECK_SECRET=1234

REVALIDATE_INTERVAL=5
HTTP_PROXY=http://proxy.digg.se:8080
HTTP_PROXY_USER=secretuser
HTTP_PROXY_PASS=secretpass

# Connect to a local backend.
#APOLLO_URL=http://localhost:1301
#REACT_APP_APOLLO_URL=http://localhost:1301
#IMAGE_DOMAIN=localhost
#REACT_APP_MEDIA_BASE_URL=http://localhost:1337

# Connect to production backend. (dataportal.se).
APOLLO_URL=https://graphql.digg.se/
REACT_APP_APOLLO_URL=https://graphql.digg.se/
IMAGE_DOMAIN=graphql.digg.se
REACT_APP_MEDIA_BASE_URL=https://graphql.digg.se/assets/dataportal_v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ yarn-error.log*
# misc
.DS_Store
*.pem
.idea/

# debug
npm-debug.log*
Expand Down
115 changes: 45 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,90 +1,62 @@
# Sveriges dataportal webbklient
![Swedish data portal](https://www.dataportal.se/images/svdp-favicon-64.png)
# The Swedish data portal web client – [dataportal.se](https://www.dataportal.se)
Sweden´s national data portal gathers and shares data for re-use to make it easier for users to find and explore it across sectors and domains.The portal only contains information about datasets, i.e. metadata. The actual datasets are retrieved via links for download or requested by the respective organization responsible for their own datasets. The Agency for Digital Government (DIGG) is responsible for Sweden's national data portal.

![node-current](https://img.shields.io/badge/node-16.13.2-green)
![npm-current](https://img.shields.io/badge/npm-8.1.2-green)
![nextjs-current](https://img.shields.io/badge/nextjs-12.1.6-green)

Här finns källkoden för dataportalens webbklient
[https://www.dataportal.se](https://www.dataportal.se)

## EntryScape

Den svenska dataportalen är starkt integrerad med produktsviten EntryScape från MetaSolutions AB, [https://entryscape.com/sv/](https://entryscape.com/sv/).
EntryScape Registry är en lösning för att hantera ett register över datakataloger och relaterad information.

## Content backend
## Entryscape
[<img alt="Entryscape logotype" src="https://entryscape.com/wp-content/uploads/2023/01/Entryscape-by-Metasolutions-w385px-Retina-2.png" width="191" height="42">](https://entryscape.com/en)

Utvecklarportalen hämtar innehåll via Apollo Gateway. Sätts via env.
The Swedish data portal is tightly integrated with the EntryScape product suite from MetaSolutions AB.
EntryScape Registry is a solution for managing a registry of data catalogs and related information

## Environment
## Requirements
![node-current](https://img.shields.io/badge/node-16.13.2-green)
![npm-current](https://img.shields.io/badge/npm-8.1.2-green)
![nextjs-current](https://img.shields.io/badge/nextjs-12.1.6-green)

Skapa en .env.local

```sh
LOGSTASH_MODE=tcp
LOGSTASH_HOST=localhost
LOGSTASH_PORT=5000
LOGGING_LEVELS=warn,error,info
LOGFILE_PATH=/app/dataportal.log
PORT=3000
HOST=http://localhost:$PORT
APOLLO_URL=http://localhost:1301 #server apollo client
REACT_APP_APOLLO_URL=http://localhost:1301 #browser apollo client
IMAGE_DOMAIN=localhost
REACT_APP_MEDIA_BASE_URL=http://localhost:1337
REACT_APP_RUNTIME_ENV=dev
HTTP_PROXY=http://proxy.digg.se:8080
HTTP_PROXY_USER=secretuser
HTTP_PROXY_PASS=secretpass

HEALTHCHECK_SECRET=123
```

## Utveckling
## Development
Start by creating an ```.env.local``` file. Use the ```.env.local.example``` as template.
(Environment variables and tokens in .env.local.example that has placeholder value of "secret" is not available here and needs to be changed to a valid value).

```sh
### Run application in development mode
Starts the application in development mode with hot-code reloading, error reporting, and more. See [Nextjs Development](https://nextjs.org/docs/app/api-reference/next-cli#development) for more information.
Run:
```sh
yarn
yarn dev
```
Visit [http://localhost:3000](http://localhost:3000) in the browser.

Gå till [http://localhost:3000](http://localhost:3000) i din webbläsare.

## Lokal server

För att testa applikationen kör följande:
### Run application in production mode
Builds the application for production usage. See [Nextjs production build](https://nextjs.org/docs/app/api-reference/next-cli#build) for more info.
And Start the Next.js production server. See [Nextjs start production](https://nextjs.org/docs/app/api-reference/next-cli#production) for more info.

Use real data from dataportalen.se by using the variables under "Connect to production backend. (dataportal.se)." in env.local.example file.
Run:
```sh
yarn
yarn build
yarn start
```
Visit [http://localhost:3000](http://localhost:3000) in the browser.

Besök [http://localhost:3000](http://localhost:3000) i din webbläsare.

## Produktionsbygge

Bygg för produktion genom att köra följande:

```sh
yarn build
```

Detta kommer generera applikationen som statiska filer under .next-mappen.

## Docker
### Run application with Docker

```sh
#bygg image
#build image
docker build . -t nextjs-dataportal

#skapa container
#create container
docker run -p 3002:3002 -e PORT=3002 -e HOST=http://localhost:3002 -e REACT_APP_APOLLO_URL=http://localhost:1400 -e REACT_APP_RUNTIME_ENV=prod -e IMAGE_DOMAIN=host.docker.internal -e REACT_APP_MEDIA_BASE_URL="http://host.docker.internal:1400/assets/dataportal" --add-host=host.docker.internal:host-gateway nextjs-dataportal
```

## Health check
### Health check

NextJs svarar på [http://localhost:1300/api/healthcheck?secret=[HEALTHCHECK_SECRET från env]](http://localhost:1300/api/healthcheck?secret=)
Cacheas inte, gör en request till contentbackend med startsidans fråga.
NextJs answers on [http://localhost:1300/api/healthcheck?secret=[HEALTHCHECK_SECRET from env]](http://localhost:1300/api/healthcheck?secret=)
Not cached, make a request to the content backend with the home page's query.

```sh
{"status":"fail"}
Expand All @@ -95,14 +67,17 @@ Cacheas inte, gör en request till contentbackend med startsidans fråga.
```

## Stack

- [Nextjs](https://nextjs.org/) JS framework
- [TypeScript](https://www.typescriptlang.org/) typad JS
- [React](https://reactjs.org/) för UI
- [Emotion](https://emotion.sh) för styling
- [Apollo Client](https://www.apollographql.com/docs/react/) för datahämtning

## Noteringar

Projektet har ett beroende till Diggs designsystemspaket `@digg/design-system`.
I skrivande stund är källkoden till detta paket inte publicerad på Github eller NPM.
- [![Nextjs](https://badgen.net/badge/Nextjs/JS%20framework/blue)](https://nextjs.org/)
- [![TypeScript](https://badgen.net/badge/TypeScript/For%20static%20types/blue)](https://www.typescriptlang.org/)
- [![React](https://badgen.net/badge/React/For%20UI/blue)](https://reactjs.org/)
- [![Emotion](https://badgen.net/badge/Emotion/For%20styling/blue)](https://emotion.sh)
- [![Apollo Client](https://badgen.net/badge/Apollo%20Client/For%20federated%20content/blue)](https://www.apollographql.com/docs/react/)

## Notes
### Content backend
The Swedish Dataportal consumes news and content via a GraphQL proxy. The content is
rendered with Apollo GraphQl and React. The proxy is not published on Github.

### Component library
The project has a dependency to [Digg component library](https://github.com/DIGGSweden/react-component-library).
The package is published via NMP under [`@digg/design-system`](https://www.npmjs.com/package/@digg/design-system)
2 changes: 1 addition & 1 deletion components/EntrystoreProvider/EntrystoreProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const EntrystoreProvider: React.FC<EntrystoreProviderProps> = ({
'#scriptsPlaceholder',
`
<script
src="https://dataportal.azureedge.net/cdn/entrystore_2021-03-18.js"
src="/entrystore_2021-03-18.js"
crossorigin="anonymous"></script>
`,
{
Expand Down
2 changes: 1 addition & 1 deletion components/Search/SearchProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class SearchProvider extends React.Component<SearchProviderProps, SearchContextD
'#scriptsPlaceholder',
`
<script
src="https://dataportal.azureedge.net/cdn/entrystore_2021-03-18.js"
src="/entrystore_2021-03-18.js"
crossorigin="anonymous"></script>
`,
{
Expand Down
2 changes: 1 addition & 1 deletion components/pages/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const SearchPage: React.FC<SearchProps> = () => {
const [showFilter, setShowFilter] = useState(false);
const [showTip, setShowTip] = useState(false);
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion components/pages/SearchSpecificationsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const SearchSpecificationsPage: React.FC<SearchProps> = () => {
const [query, setQuery] = useState('');
const [showFilter, setShowFilter] = useState(false);
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion components/pages/SearchTermsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const SearchTermsPage: React.FC<SearchProps> = () => {
const [query, setQuery] = useState('');
const [showFilter, setShowFilter] = useState(false);
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion pages/concepts/[concept]/[param].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function Concept() {
const curi = `${concept}/${param}`;
const entryUri = `https://dataportal.se/concepts/${curi}`;
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion pages/concepts/[concept]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function Concept() {
const curi = concept;
const entryUri = `https://dataportal.se/concepts/${curi}`;
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion pages/dataservice/[dataSet]/[name].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function ExploreApiPage() {
const cid = ids[0];
const eid = ids[1];
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion pages/dataservice/[dataSet]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function ExploreApiPage() {
const cid = ids[0];
const eid = ids[1];
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion pages/datasets/[dataSet]/[name]/apiexplore/[apieid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function ExploreApiPage() {
const cid = ids[0];
const eid = ids[1];
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion pages/datasets/[dataSet]/[name]/apiexplore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function DataSet() {
const cid = ids[0];
const eid = ids[1];
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion pages/datasets/[dataSet]/[name]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function DataSet() {
const cid = ids[0];
const eid = ids[1];
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion pages/datasets/[dataSet]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function DataSet() {
const cid = ids[0];
const eid = ids[1];
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion pages/externalconcepts/[...concept].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function Concept() {
const curi = paths.join('/');
const entryUri = `${scheme}://${curi}`;
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion pages/externalterminology/[...concept].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function Concept() {
const curi = paths.join('/');
const entryUri = `${scheme}://${curi}`;
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion pages/specifications/[...paths].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function Concept() {
const curi = (paths as string[])?.join('/');
const entryUri = `https://dataportal.se/specifications/${curi}`;
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion pages/terminology/[terminology]/[param].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function Concept() {
const curi = `${terminology}/${param}`;
const entryUri = `https://dataportal.se/concepts/${curi}`;
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
2 changes: 1 addition & 1 deletion pages/terminology/[terminology]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function Concept() {
const curi = terminology;
const entryUri = `https://dataportal.se/concepts/${curi}`;
const postscribeStatus = useScript(
'https://dataportal.azureedge.net/cdn/postscribe.min.js',
'/postscribe.min.js',
'sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM',
'anonymous'
);
Expand Down
8 changes: 8 additions & 0 deletions public/entrystore_2021-03-18.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions public/postscribe.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion utilities/generateCsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const generateCSP = ({ nonce }: generateCSPProps = {}) => {
'script-src',
`'self' ${
nonce ? `'nonce-${nonce}'` : ''
} 'strict-dynamic' 'unsafe-eval' 'unsafe-inline' https://webbanalys.digg.se https://dataportal.azureedge.net *.entryscape.com *.dataportal.se`,
} 'strict-dynamic' 'unsafe-eval' 'unsafe-inline' https://webbanalys.digg.se *.entryscape.com *.dataportal.se`,
{ prodOnly: true }
);
add(
Expand Down

0 comments on commit bb2765e

Please sign in to comment.