-
Notifications
You must be signed in to change notification settings - Fork 19
Get geolocation about a given IP address #138
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
28779ba
23df1d1
fc08d73
0b966f4
7224f68
e70054b
97c4ec6
f7246fc
5a3506c
37271a3
4473889
5a97097
77ca319
6f4f8be
84bd996
3cd7cf2
1dc6920
5ec7b1b
9616015
2a83ae9
9c5177e
629c057
665dd7d
44347b6
d9f1270
f284d67
262f214
9d67bc5
bbafc46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for this resource! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ) |
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') | ||
ewdurbin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const token = await configStore.get('token') | ||
|
||
// If the value doesn't exist or is false, return Unauthorized | ||
if (!token) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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({ | ||
|
@@ -14,7 +27,7 @@ async function app(event) { | |
country_name: geo.country_name, | ||
region: geo.region, | ||
}, | ||
}) | ||
}); | ||
|
||
return new Response( respBody, { | ||
headers: { | ||
|
Uh oh!
There was an error while loading. Please reload this page.