opinion-poll v1.0.0
Opinion Poll server
Expressjs server for the Opinion Poll machinery.
General structure
The "output" of this project is a single http server which hosts a number of things:
- the
/admin
endpoint which contains the admin interface. - the
/public
endpoint which contains the all frontend components. - the
/oembed
endpoint which returns an oEmbed json. The HTML component of this is an iframe that links to the/public
endpoint above. - the
/api
api which allows you to upload files to the database and fetch data from the database.
All routes are prefixed: /tjenester/meningsmaalinger
Embed URL structure
Url structure used for embedding passes props as query, like this:
{HOST}{PREFIX}/public/{ELEMENT}?{PROP NAME}={PROP VALUE}&{PROP NAME}={PROP VALUE}
Some examples:
http://localhost:5000/tjenester/meningsmaalinger/public/deviations?fromId=23&toId=12&allowUnitToggle=true&segment=men&allowSegmentToggle=true&showMandates=true
http://localhost:5000/tjenester/meningsmaalinger/public/candidate-movement?id=1&selectedId=9&showControls=true
Database
The application use a Postgres database to hold opinion poll data. Three google cloud instances are created:
- test
- preprod
- prod
Local environment
You can either use docker or npm for local development.
Without local database
Use npm npm install && npm run start:watch
For this to work, you need to have environment variables defined for database connection. See .env.dist
.
For local use, connect only to test
database.
With local database
To start a local environment with a local database, run: npm i && docker-compose up -d --build
.
If you want to run migrations on your local database, go to {HOST}/admin/system/migrate
.
Default is: http://localhost:5000/tjenester/meningsmaalinger/admin/system/migrate
Here you can migrate to latest or roll back.
Use local Poll-Elements package
If you want to use a local version of Poll-Elements without publishing, you can follow the example in docker-compose.yml.
Authentication
test, preprod and prod is using DR SAML authentication, setting the AUTH enviroment variable to false
, disable authentication.
Generate Service Provider certificate.
SAML Service Provider (SP) needs a self signed certificate, one for each environment. The ones generated last for 10 yeas. however if they need to be updated this is the command used for generation:
openssl req -newkey rsa:4096 -new -x509 -days 3652 -nodes -keyout sp.key -out sp.crt -subj "/C=DK/L=Copenhagen>/O=Danish Broadcasting Corporation/CN=preprod.dr.dk/EA=info@dr.dk"
Change the "-subj" argument "CN", to the host name for which the certificate is generated for.
DR Routes
PROD: https://www.dr.dk/tjenester/meningsmaalinger/ https://opinion-poll.public.prod.gcp.dr.dk/tjenester/meningsmaalinger/
PREPROD https://preprod.dr.dk/tjenester/meningsmaalinger/ https://opinion-poll.public.preprod.gcp.dr.dk/tjenester/meningsmaalinger/
TEST https://test.dr.dk/tjenester/meningsmaalinger/ https://opinion-poll.public.test.gcp.dr.dk/tjenester/meningsmaalinger/
4 years ago