-
Notifications
You must be signed in to change notification settings - Fork 365
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
feat: add geolocation data to Netlify Dev #4566
Conversation
📊 Benchmark resultsComparing with 2c58896 Package size: 273 MB(no change)
Legend
|
It might be good to add a check for user-agent in the API, to stop somebody deciding to use it as a free, unlimited geoip service |
The service will return geolocation data only for the requesting IP, as opposed to accepting an IP address as input, so it will be less useful as a service? Also, I'm not sure that checking the UA will help, since it can be easily spoofed. |
The scenario I'm thinking about is somebody using it in their site to get the visitor's IP. It wouldn;t be spoofable then as it's the user's browser. |
long-term we should require an api token from the user. We can't easily build that in right now because the api tokens can only be verified by bitballoon and not as stateless JWTs. technically anybody could build such an api with edge functions though. it would just be easier for us to kick them off our service. |
you don't need to verify the user-agent though since CORS prevents usage from other websites through browsers |
I do forget that CORS exists for purposes other than wasting mornings on broken header configurations. |
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.
LGTM
still slightly terrified of reviewing non-typescript code 🙈
And I'm terrified of writing it! 🙊 |
It's not quite the same, but |
Totally. We've been doing this in every new file we add to the CLI, and it was missing from this PR. Added in 2f6c520. I've also fixed some tests. Could I get another ✅ , please? |
Summary
Adds geolocation data to Netlify Dev when using Edge Functions. It retrieves the geolocation data from https://netlifind.netlify.app/ and caches it locally for 24h, to avoid making a request every time the app starts.
When the request fails, or when CLI is used with the
--offline
flag, we use a mock location (San Francisco).A new
--geo
flag is added to thedev
command with the following values:cache
(default): Uses the geolocation cached locally if it's not older than 24h. Otherwise, it retrieves it from the API.update
: Retrieves geolocation data from the API, even if there is a cached version.mock
: Does not make any requests to the API and uses the mock location.