Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions fastly-compute/geoip/fastly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ service_id = "CnsNqIdpSj1tZNLTl6PUi4"

[scripts]
build = "npm run build"

[local_server]
[local_server.config_stores]
[local_server.config_stores.strings]
file = ".secret.json"
format = "json"

15 changes: 14 additions & 1 deletion fastly-compute/geoip/src/index.js
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: ‏overall, run the js code through Prettier to get consistent style. There's a live playground here: https://prettier.io/playground/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for this resource!

Copy link
Member

@miketheman miketheman Jun 30, 2023

Choose a reason for hiding this comment

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

Might be useful to rerun prettier again.

(Also looks like per-file comments can't be resolved. FYI @github )
(Maybe that's a permissions thing though?)

Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
/// <reference types="@fastly/js-compute" />

import { getGeolocationForIpAddress } from "fastly:geolocation"
import { ConfigStore } from "fastly:config-store";

async function app(event) {
try {
const configStore = new ConfigStore('strings')
const token = await configStore.get('token')

// If the value doesn't exist or is false, return Unauthorized
if (!token) {
Copy link
Member

Choose a reason for hiding this comment

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

question: ‏what determines if the token is supplied by the caller and is compared to the token retrieved from the config store?

let respBody = JSON.stringify({ Error: "Unauthorized" });
return new Response(respBody, {
status: 401,
headers: { 'Content-Type': 'application/json' }
});
}
let ip = new URL(event.request.url).searchParams.get('ip') || event.client.address
let geo = getGeolocationForIpAddress(ip);
let respBody = JSON.stringify({
Expand All @@ -14,7 +27,7 @@ async function app(event) {
country_name: geo.country_name,
region: geo.region,
},
})
});

return new Response( respBody, {
headers: {
Expand Down