Skip to content

Conversation

michelleN
Copy link
Member

  • requires api token for weather site
  • can provide an ip addr to test with

SPIN_VARIABLE_TEST_IP_ADDR= SPIN_VARIABLE_WAQI_API_TOKEN= spin up

@michelleN michelleN force-pushed the weatherapp branch 2 times, most recently from 7d5a4c5 to a2a679b Compare February 20, 2025 20:19
@michelleN michelleN marked this pull request as ready for review February 20, 2025 20:19
+ 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]>
@@ -0,0 +1,31 @@
const getClientAddressFromRequest = (req: Request): string | null => {
Copy link
Member Author

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

Copy link
Collaborator

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

Copy link
Member Author

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.

@michelleN michelleN linked an issue Feb 20, 2025 that may be closed by this pull request
@michelleN michelleN force-pushed the weatherapp branch 2 times, most recently from 6e0899c to 1114c8e Compare February 20, 2025 21:54
addEventListener('fetch', async (event: FetchEvent) => {
let token = Variables.get("waqi_api_token");
if (!token) {
event.respondWith(new Response("Internal Server Error", {status: 500}));
Copy link
Contributor

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.

Copy link
Member Author

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]>
@michelleN michelleN marked this pull request as draft February 20, 2025 22:42
@michelleN michelleN marked this pull request as ready for review February 21, 2025 18:09
@michelleN
Copy link
Member Author

@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");
Copy link
Contributor

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.

Copy link
Member

@vdice vdice Jul 15, 2025

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}:/;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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");
Copy link
Member

@vdice vdice Jul 15, 2025

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"));
Copy link
Member

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.

@vdice
Copy link
Member

vdice commented Jul 15, 2025

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?

@vdice vdice requested a review from karthik2804 July 15, 2025 10:32
@karthik2804
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add geolocation example
4 participants