Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get geolocation about a given IP address #138

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
28779ba
Get geolocation about a given IP address
cegerhardson Jun 2, 2023
23df1d1
Add necessary bits to run test locally, and move to new location.
cegerhardson Jun 6, 2023
fc08d73
Add Github Actions to deploy Fastly's Compute@Edge: getGeolocationFor…
cegerhardson Jun 6, 2023
0b966f4
Place deploy-geoip.yaml in the correct location to be triggered
cegerhardson Jun 6, 2023
7224f68
Prepare for testing, and delete old file paths.
cegerhardson Jun 6, 2023
e70054b
Add project_directory value
cegerhardson Jun 6, 2023
97c4ec6
Move project_diretory value
cegerhardson Jun 6, 2023
f7246fc
Trying to fix path bug.
cegerhardson Jun 7, 2023
5a3506c
Trying again
cegerhardson Jun 7, 2023
37271a3
Just trying
cegerhardson Jun 7, 2023
4473889
Fingers-crossed
cegerhardson Jun 7, 2023
5a97097
Testing for auth
cegerhardson Jun 7, 2023
77ca319
Maybe?
cegerhardson Jun 7, 2023
6f4f8be
Update fastly-compute/geoip/fastly.toml
cegerhardson Jun 8, 2023
84bd996
Update fastly-compute/geoip/fastly.toml
cegerhardson Jun 8, 2023
3cd7cf2
Add Github Actions to deploy Fastly's Compute@Edge: getGeolocationFor…
cegerhardson Jun 6, 2023
1dc6920
Include region in geolocation return values.
cegerhardson Jun 8, 2023
5ec7b1b
Merge branch 'ComputeAtEdge_Test' of https://github.com/python/pypi-i…
cegerhardson Jun 9, 2023
9616015
Add Service ID
cegerhardson Jun 13, 2023
2a83ae9
Add authentication configuration via Fastly's ConfigStore.
cegerhardson Jun 15, 2023
9c5177e
Add necessary file for configuation
cegerhardson Jun 15, 2023
629c057
Update fastly-compute/geoip/.secret.json
ewdurbin Jun 15, 2023
665dd7d
Update README
cegerhardson Jun 27, 2023
44347b6
Update service description
cegerhardson Jun 27, 2023
d9f1270
Reconfigure authentication and prettify
cegerhardson Jun 27, 2023
f284d67
Update
cegerhardson Jun 28, 2023
262f214
Update references
cegerhardson Jun 29, 2023
9d67bc5
change config store name
cegerhardson Jun 30, 2023
bbafc46
get rid of try/catch
cegerhardson Jun 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions compute-at-edge-test/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// <reference types="@fastly/js-compute" />
ewdurbin marked this conversation as resolved.
Show resolved Hide resolved

import { getGeolocationForIpAddress } from "fastly:geolocation"
async function app(event) {
try {
let ip = new URL(event.request.url).searchParams.get('ip') || event.client.address
let geo = getGeolocationForIpAddress(ip);
let respBody = JSON.stringify({
geo: {
city: geo.city,
continent: geo.continent,
country_code: geo.country_code,
country_code3: geo.country_code3,
country_name: geo.country_name,
region: null,
},
})

return new Response( respBody, {
headers: {
"Content-Type": "application/json",
},
});
} catch (error) {
console.error(error);
return new Response("Internal Server Error", {
status: 500
});
}
}

addEventListener("fetch", (event) => event.respondWith(app(event)));
18 changes: 18 additions & 0 deletions fastly-compute/geoip/.github/workflows/deploy-geoip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Deploy Compute@Edge GeoIp
ewdurbin marked this conversation as resolved.
Show resolved Hide resolved
on:
push:
branches: [main]
ewdurbin marked this conversation as resolved.
Show resolved Hide resolved

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install project dependencies
run: npm install

- name: Deploy to Compute@Edge
uses: fastly/compute-actions@v5
env:
FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }}
3 changes: 3 additions & 0 deletions fastly-compute/geoip/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
/bin
/pkg
11 changes: 11 additions & 0 deletions fastly-compute/geoip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Empty Starter Kit for JavaScript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this doc with some helpful information!

I'd suggest at a minimum:

  • Changing the title
  • Giving a brief description of what this service does
  • Adding some notes on how to work on it locally (npm install, commands to start the server, etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely makes sense, I'll be sure to work this read.me over.


[![Deploy to Fastly](https://deploy.edgecompute.app/button)](https://deploy.edgecompute.app/deploy)

An empty application template for the Fastly Compute@Edge environment which simply returns a 200 OK response.

**For more details about other starter kits for Compute@Edge, see the [Fastly developer hub](https://developer.fastly.com/solutions/starters)**

## Security issues

Please see our [SECURITY.md](SECURITY.md) for guidance on reporting security-related issues.
12 changes: 12 additions & 0 deletions fastly-compute/geoip/fastly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file describes a Fastly Compute@Edge package. To learn more visit:
# https://developer.fastly.com/reference/fastly-toml/

authors = ["[email protected]"]
description = "Test"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: ‏update description

language = "javascript"
manifest_version = 3
name = "Compute@Edge Test"
cegerhardson marked this conversation as resolved.
Show resolved Hide resolved
service_id = ""
cegerhardson marked this conversation as resolved.
Show resolved Hide resolved

[scripts]
build = "npm run build"
Loading