Skip to content

Commit

Permalink
TFL have removed app_id from their API calls. Therefore, we can sim…
Browse files Browse the repository at this point in the history
…plify the environment varibles needed here and just have a single one for `app_key`.
  • Loading branch information
lucas42 committed Jan 5, 2023
1 parent ab6aa73 commit cf940a9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
npm-debug.log
bin
reports
reports
.env
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ To run unit tests using [ava](https://github.com/avajs/ava), run:
* ```npm start```

You should also set the following environment variables:
TFLAPPID and TFLAPPKEY - information about TFL's API can be found at https://api-portal.tfl.gov.uk/docs
The app appears to run fine without these being set, but registering for an ID and key helps to keep track of which apps are making which requests to the API.
TFL_KEY - generated here: https://api-portal.tfl.gov.uk/profile
The app appears to run fine without these being set, but registering for a key helps to keep track of which apps are making which requests to the API and increases the limit of requests that can be made.

## Running using docker compose
`TFLAPPID=<id> TFLAPPKEY=<secret> nice -19 docker-compose up -d --no-build`
`TFL_APP=<secret> nice -19 docker-compose up -d --no-build`

## Building
The build is configured to run in Dockerhub when a commit is pushed to the master branch in github.
3 changes: 1 addition & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ services:
ports:
- "3000:3000"
environment:
- TFLAPPID
- TFLAPPKEY
- TFL_KEY
image: lucas42/tfluke_app
restart: always
5 changes: 2 additions & 3 deletions src/fetchers/tfl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ function tflapireq(path) {
} else {
url += '?';
}
url += "app_id="
if (process.env.TFLAPPID) url += encodeURIComponent(process.env.TFLAPPID);
url += "&app_key=";
if (process.env.TFLAPPKEY) url += encodeURIComponent(process.env.TFLAPPKEY);
if (process.env.TFL_KEY) url += encodeURIComponent(process.env.TFL_KEY);
return fetch(url, {timeout: 800}).then(response => {
if (response.status == 429) throw new Error(`TFL API Rate Limited`);
if (response.status != 200) throw new Error(`Unexpected status code ${response.status}`);
return response.json().then(data => {
return {
Expand Down
4 changes: 1 addition & 3 deletions src/sources/tfl-unified.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ function tflapireq(path, callback) {
} else {
url += '?';
}
url += "app_id="
if (process.env.TFLAPPID) url += encodeURIComponent(process.env.TFLAPPID);
url += "&app_key=";
if (process.env.TFLAPPKEY) url += encodeURIComponent(process.env.TFLAPPKEY);
if (process.env.TFL_KEY) url += encodeURIComponent(process.env.TFLAPPKEY);
req(url, function (err, resp, rawbody) {
if (err) {
console.error(err);
Expand Down

0 comments on commit cf940a9

Please sign in to comment.