Skip to content

Commit 48aaad9

Browse files
Dean SoferDean Sofer
authored andcommitted
Secure apify token
1 parent a71661e commit 48aaad9

File tree

5 files changed

+102
-4
lines changed

5 files changed

+102
-4
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APIFY_TOKEN=apify_api_1234567890

.github/workflows/deploy.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- gh-pages
7+
workflow_dispatch:
8+
9+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
10+
permissions:
11+
contents: read
12+
pages: write
13+
id-token: write
14+
15+
# Allow only one concurrent deployment
16+
concurrency:
17+
group: "pages"
18+
cancel-in-progress: false
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Inject APIFY_TOKEN into map.js
28+
env:
29+
APIFY_TOKEN: ${{ secrets.APIFY_TOKEN }}
30+
run: |
31+
sed -i "s/__APIFY_TOKEN__/${APIFY_TOKEN}/g" map.js
32+
33+
- name: Setup Pages
34+
uses: actions/configure-pages@v4
35+
36+
- name: Upload artifact
37+
uses: actions/upload-pages-artifact@v3
38+
with:
39+
path: '.'
40+
41+
deploy:
42+
environment:
43+
name: github-pages
44+
url: ${{ steps.deployment.outputs.page_url }}
45+
runs-on: ubuntu-latest
46+
needs: build
47+
steps:
48+
- name: Deploy to GitHub Pages
49+
id: deployment
50+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
.env

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,42 @@ Data is refreshed every other day by Apify crawler.
66
[![Screenshot](https://proloser.github.io/funcheapmap/screenshot.png)](https://proloser.github.io/funcheapmap/)
77

88
Latest version has a button to quickly add events to your calendar of choice
9-
<img width="741" alt="Screenshot 2024-08-05 at 1 38 18 PM" src="https://github.com/user-attachments/assets/14fcbafa-13b7-447e-9f1e-d018c191983c">
9+
<img width="741" alt="Screenshot 2024-08-05 at 1 38 18 PM" src="https://github.com/user-attachments/assets/14fcbafa-13b7-447e-9f1e-d018c191983c">
10+
11+
## Setup
12+
13+
### Local Development
14+
15+
1. Copy the example environment file:
16+
```bash
17+
cp .env.example .env
18+
```
19+
20+
2. Add your Apify API token to `.env`:
21+
```
22+
APIFY_TOKEN=your_actual_apify_token_here
23+
```
24+
25+
3. Open `index.html` in your browser directly, or use a local server:
26+
```bash
27+
python -m http.server 8080
28+
# or
29+
npx http-server -p 8080
30+
```
31+
32+
### GitHub Pages Deployment
33+
34+
The site automatically deploys to GitHub Pages when you push to the `gh-pages` branch.
35+
36+
**Required GitHub Secret:**
37+
38+
You need to add your Apify API token as a GitHub secret:
39+
40+
1. Go to your repository on GitHub
41+
2. Navigate to **Settings****Secrets and variables****Actions**
42+
3. Click **New repository secret**
43+
4. Name: `APIFY_TOKEN`
44+
5. Value: Your Apify API token
45+
6. Click **Add secret**
46+
47+
The GitHub Actions workflow will automatically inject this token into the JavaScript file at build time.

map.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ window.showUserLocation = async function () {
320320
* Utility class for managing event data
321321
*/
322322
class Events {
323+
static API_TOKEN = '__APIFY_TOKEN__';
324+
static API = `https://api.apify.com/v2/acts/apify~cheerio-scraper/runs/last/dataset/items?clean=true&token=${Events.API_TOKEN}`;
323325
/**
324326
* Generates and returns a google maps info window
325327
*
@@ -473,7 +475,13 @@ class Events {
473475
*/
474476
query() {
475477
return fetch(new Request(Events.API))
476-
.then(response => response.json());
478+
.then(response => {
479+
if (!response.ok) {
480+
const error = new Error(`Events Query Failed! ${response.status}`);
481+
error.response = response;
482+
throw error;
483+
}
484+
return response.json();
485+
});
477486
}
478487
}
479-
Events.API = 'https://api.apify.com/v2/acts/apify~cheerio-scraper/runs/last/dataset/items?clean=true&token=apify_api_1U4gg8GRgTkFBjyfEkxKNtS9n4gUUw3wUjUV';

0 commit comments

Comments
 (0)