A simple Node.js + Javascript map using the Strava API
291
Simple Strava API + Javascript + Node.js + Docker solution
The code is based on the Javascript only version version by Fran Polignano. His YouTube tutorials and code on Github were very helpful for me to get started with the Strava API.
His code had a few problems though, so I tried to fix them. One major problem for me was the fact that the Strava credentials were visible in the JavaScript code, meaning anyone could gain access to your account that way. The only way that I found to fix that was by splitting the application up into two parts: a server part (build using Node.js) and a client-part (using Javascript). Using Node.js had the added benifit that I could re-use much of the code. It also allowed for 'local' (on the server) caching, which is needed due to the limits that Strava has put on the number of API call that you can make during a given timeperiod.
Because I did not want to install Node.js on my local system, I used Docker as a way to easily deploy it for the development setting and (based on the same code, just with a different way of building the Docker container) for production purposes. Documentation is still lacking, but the code is here.
All configuration is done via the .env file. Make sure you replace
client_id=1234567
client_secret=xxxxxxxxx
refresh_token=xxxxxxx
with the appropriate values.
You can also set the amount of minutes that the data is being cached through the 'expire' value. It is set to 60 (1 hour) by default, but even bigger values are usually good. In .env you can set the activities you want to ignore (add the Strava activity ID) and the types of activities (can be multiple) that you want to display. Changes to .env will only be read by node.js when the server restarts.
You can set the 'activity_since' variable to indicate how far back the script needs to go. Paging has been implemented, so it is possible to go back more than the current 60 per page activities (Strava limits the number per page to 200).
# password for internal stuff
# change!
app_key=6tuyfh456
# stuff below this line you can leave, but you might want to change them
# cache expire time in minutes
expire=60
# strava id of activities to ignore
# use ignore_activity=[] in case you don't want any to be ignored
ignore_activity=[678, 345, 123]
# what activity types to show
show_activity_types=["Walk"]
# show activities si nce
# epoch time conversion online: https://www.epochconverter.com/
activity_since=1546300800
If you want to force the clearing of the cache, go to /cache/refresh/6tuyfh456
The '6tuyfh456' part of the url is set in .env and can (should) be changed to something you only know.
To use the development setup, you need to install Docker and then run the run-docker.sh file. After that you'll be logged into the container and need to do some more things to install everything the first time:
yarn init -y
yarn add express
yarn add -D nodemon
yarn add flat-cache --ignore-engines
yarn add dotenv --ignore-engines
yarn add node-fetch --ignore-engines
with
yarn start
you can then start the server and reach it on port 8080 (not 3000!) This server stops working if you close the command window.
The run-node-strava.sh is meant to be used with a production version. First you have to build the image using
sudo docker build -t docker-strava .
Then you can use run-node-strava.sh to start a server in the background. It will run on port 8081 by default.
The repository at Github is linked to the one at Docker hub, so you only need to create an .env file like this example to run it with:
sudo docker run -d --name docker-strava-map --env-file=.env -e "PORT=3000" -p 8084:3000 -u node piair/docker-strava-map:latest
Content type
Image
Digest
Size
348.1 MB
Last updated
over 6 years ago
docker pull piair/docker-strava-map