-
Notifications
You must be signed in to change notification settings - Fork 6
add geolocation weather example #15
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?
Conversation
7d5a4c5
to
a2a679b
Compare
a2a679b
to
f6b0c6a
Compare
+ requires api token for weather site + can provide an ip addr to test with SPIN_VARIABLE_TEST_IP_ADDR=<some ip> SPIN_VARIABLE_WAQI_API_TOKEN=<some token> spin up Signed-off-by: Michelle Dhanani <[email protected]>
f6b0c6a
to
1a9e1a2
Compare
@@ -0,0 +1,31 @@ | |||
const getClientAddressFromRequest = (req: Request): string | null => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ThorstenHans I borrowed this from one of your js samples. It'd be great to figure out how to consolidate this logic to be used across multiple sample apps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, what are you thinking about? Sharing this across multiple apps/examples would either lead to a local or published npm package.
IMO, being repetitive here is okay, for the sake of each sample being holistic.
Or had you something different in mind @michelleN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, npm package was along the lines of what I was thinking but good point on being repetitive for the sake of being holistic. I think we should keep it as is.
3da16f5
to
5be7c13
Compare
6e0899c
to
1114c8e
Compare
addEventListener('fetch', async (event: FetchEvent) => { | ||
let token = Variables.get("waqi_api_token"); | ||
if (!token) { | ||
event.respondWith(new Response("Internal Server Error", {status: 500})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would also possibly make sense to leave a console.log here as to why the request failed to make it easier to debug. My apologies for not leaving it with the previous review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated 👍
Co-authored-by: Karthik Ganeshram <[email protected]> Signed-off-by: Michelle Dhanani <[email protected]>
1114c8e
to
efa736b
Compare
Signed-off-by: Michelle Dhanani <[email protected]>
@karthik2804 @ThorstenHans I think I've resolved all feedback. If ya'll could take another look, I'd appreciate it. |
@@ -0,0 +1,31 @@ | |||
const getClientAddressFromRequest = (req: Request): string | null => { | |||
const clientAddress = req.headers.get("spin-client-addr"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this issue would lead us to use a different approach here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's true that this header is now considered optional and that it isn't currently provided to guest apps on FwF. However, since this example is also built to run locally, this seems fine to leave in (since "true-client-ip" isn't present for spin up
), noting that a suitable replacement is still pending.
}; | ||
|
||
const cleanupIpAddress = (input: string): string => { | ||
const ipv4Regex = /^(\\d{1,3}\\.){3}\d{1,3}:/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const ipv4Regex = /^(\\d{1,3}\\.){3}\d{1,3}:/; | |
const ipv4Regex = /^(\d{1,3}\.){3}\d{1,3}$/; |
@@ -0,0 +1,31 @@ | |||
const getClientAddressFromRequest = (req: Request): string | null => { | |||
const clientAddress = req.headers.get("spin-client-addr"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's true that this header is now considered optional and that it isn't currently provided to guest apps on FwF. However, since this example is also built to run locally, this seems fine to leave in (since "true-client-ip" isn't present for spin up
), noting that a suitable replacement is still pending.
}); | ||
|
||
async function getWeather(request: Request, token: string): Promise<Response> { | ||
console.log("Request received", request.headers.get("spin-client-addr")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I think the instance of this header in https://github.com/fermyon/fwf-examples/pull/15/files#r2035295960 is fine and should stay, we probably should remove printing it here, since it will be null
when running on FWF.
Signed-off-by: Vaughn Dice <[email protected]>
Since @michelleN is out, I took the liberty to push a commit addressing my requested changes. @karthik2804 and/or @ThorstenHans could you re-review when convenient? |
It looks like we already have a geo-ip example in the repo https://github.com/fermyon/fwf-examples/tree/main/samples/geo-ip. Do we want another? |
SPIN_VARIABLE_TEST_IP_ADDR= SPIN_VARIABLE_WAQI_API_TOKEN= spin up