Mocked-API
Mocked-API copied to clipboard
Analytics supporting changes and infrastructure.
Pull request template
IMPORTANT: Please review the CONTRIBUTING.md file for detailed contributing guidelines.
Describe your changes
Link to issue this resolves
Screenshot of changes(if relevant)
- Added a new environment variable PLAUSIBLE_CONFIGURATION to the .env.example file
- Added plausibleLogger middleware in app.ts
- Updated docker-compose with Plausible Analytics Engine configuration and added volumes for data persistence
- Created console-analytics middleware as an example of how to implement custom analytics logging (not used)
- Created plausible middleware that logs all requests into Plausible Analytics Engine
- Create public/custom1,js which is loaded by swagger UI when it loads /docs endpoint (this script adds the tracking code from Plausible)
This Pull request is for @ageddesi to see what I managed to get working. Getting it working locally is somewhat of a challenge,
FIrstly you need an address that ISN'T localhost - so running this locally you will need a host file entry - depending on your envurinment add an entry in yourt host file. I have been testing this with the following host entry
127.0.0.1 MockedApi.local
You will need a plausible.conf file - an example is included. You will need a secret - most of this is taken from : https://plausible.io/docs/self-hosting
create a secret and add it to the .plausible configuration file
$ openssl rand -base64 64 | tr -d '\n' ; echo
now stand the docker-compose file up - at the end of this you should have the following conainers running

I turned off mockedAPI as I run locally
you can connect to plausible at : http://localhost:8000/
you can connect to the API at http://mockedapi.local:3000/
logging into plausible you need to add a website - so add a site for mockedpi.local.
There is a Javascript file that needs to be added (i created custom.js to register that - will work on making it more generic) - which should send the request to plausible.
hope these somewhat hasty instructions are going to b ok for you.
gotchas : Make sure you browse to http://mockedapi.local:3000 - if you hit localhost:3000 then the adress that will be passed to plausible will be ignore and you'll see no traffic
what's wrong with this pr??
what's wrong with this pr??
I had been chatting to @ageddesi about analytics - and he asked for a PR to see what I had managed to do - I had some questions or thoughts about how we log visits to API end points.
The tests are failing because the middleware I have developed for analystics is having some problem with environment settings.
I am rebasing this branch and will update as soon as I pick apart what has changed since I first set up this branch