-
Notifications
You must be signed in to change notification settings - Fork 2
Rename geotargeting to georouting and simplify to per-region edge hosts #308
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
Open
etiennelatendresse-optable
wants to merge
2
commits into
master
Choose a base branch
from
tweak-and-rename-geotargeting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+87
−176
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { getGeoRouting, DEFAULT_GEO_MAP } from "./geo-routing.ts"; | ||
|
|
||
| describe("getGeoRouting", () => { | ||
| test("resolves the edge host for each supported region", () => { | ||
| expect(getGeoRouting("NA")).toBe("na.edge.optable.co"); | ||
| expect(getGeoRouting("CA")).toBe("ca.edge.optable.co"); | ||
| expect(getGeoRouting("EU")).toBe("eu.edge.optable.co"); | ||
| expect(getGeoRouting("AU")).toBe("au.edge.optable.co"); | ||
| }); | ||
|
|
||
| test("returns null for an unsupported region", () => { | ||
| expect(getGeoRouting("SA")).toBeNull(); | ||
| }); | ||
|
|
||
| test("returns null for a missing region", () => { | ||
| expect(getGeoRouting("")).toBeNull(); | ||
| expect(getGeoRouting(undefined)).toBeNull(); | ||
| }); | ||
|
|
||
| test("returns null for regions inherited from Object.prototype", () => { | ||
| expect(getGeoRouting("constructor")).toBeNull(); | ||
| expect(getGeoRouting("__proto__")).toBeNull(); | ||
| expect(getGeoRouting("toString")).toBeNull(); | ||
| }); | ||
|
|
||
| test("is case-sensitive on the region key", () => { | ||
| expect(getGeoRouting("na")).toBeNull(); | ||
| }); | ||
|
|
||
| test("accepts a custom geo map", () => { | ||
| const geoMap = { SA: "sa.edge.optable.co" }; | ||
| expect(getGeoRouting("SA", geoMap)).toBe("sa.edge.optable.co"); | ||
| expect(getGeoRouting("NA", geoMap)).toBeNull(); | ||
| }); | ||
|
|
||
| test("exposes the default geo map", () => { | ||
| expect(DEFAULT_GEO_MAP.NA).toBe("na.edge.optable.co"); | ||
| expect(DEFAULT_GEO_MAP.CA).toBe("ca.edge.optable.co"); | ||
| expect(DEFAULT_GEO_MAP.EU).toBe("eu.edge.optable.co"); | ||
| expect(DEFAULT_GEO_MAP.AU).toBe("au.edge.optable.co"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * The geo-routing addon maps a visitor's region code to the Optable edge host | ||
| * that should serve them, so a single SDK bundle can route traffic to the | ||
| * regional edge closest to (and provisioned for) the visitor. | ||
| * | ||
| * Keys are region codes (not country codes) that map 1:1 to Optable edge hosts. | ||
| * Translating a visitor's country code to a region code is the caller's | ||
| * responsibility — the addon deliberately knows only regions, not the full | ||
| * country-to-region table. The caller also supplies the SDK `node`/`site`; | ||
| * this addon only resolves the host. | ||
| */ | ||
|
|
||
| export type GeoMap = Record<string, string>; | ||
|
|
||
| export const DEFAULT_GEO_MAP: GeoMap = { | ||
| AU: "au.edge.optable.co", | ||
| CA: "ca.edge.optable.co", | ||
| EU: "eu.edge.optable.co", | ||
| NA: "na.edge.optable.co", | ||
| }; | ||
|
|
||
| /* | ||
| * getGeoRouting() resolves the Optable edge host for a given region code. | ||
| * | ||
| * Returns null when the region is missing or not present in the map, in which | ||
| * case the caller should skip region-specific initialization. | ||
| */ | ||
| export function getGeoRouting(region: string | undefined, geoMap: GeoMap = DEFAULT_GEO_MAP): string | null { | ||
| // hasOwnProperty guards against inherited Object.prototype members being | ||
| // picked up when an unexpected region like "constructor" is looked up. | ||
| if (region === undefined || !Object.prototype.hasOwnProperty.call(geoMap, region)) { | ||
| return null; | ||
| } | ||
| return geoMap[region]; | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should be
US: "na.edge.optable.co"instead ofNA: "na.edge.optable.co". We could support both though.