Skip to content

Commit f4dd297

Browse files
committed
MVP: main page working
1 parent 1bd23f7 commit f4dd297

File tree

13 files changed

+300
-0
lines changed

13 files changed

+300
-0
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = lf
9+
indent_size = tab
10+
insert_final_newline = true
11+
tab_width = 4
12+
trim_trailing_whitespace = true
13+
14+
[*.json]
15+
indent_size = 2
16+
17+
[*.yaml]
18+
indent_size = 2

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
*~
2+
build.json
3+
.cache
4+
*.class
5+
crash.log
6+
.DS_Store
7+
.env
8+
.idea/
9+
.jekyll-metadata
10+
node_modules
11+
*.pyc
12+
.sass-cache/
13+
_site/
14+
tmp/
15+
_tmp/
16+
venv/
17+
18+
# Local Netlify folder
19+
.netlify

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source "https://rubygems.org"
2+
3+
gem "jekyll"
4+
gem "jekyll-redirect-from"

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Netlify Geolocation [<img alt="Geolocation logo" src="docs/favicon.svg" height="90" align="right" />](https://netlify-geo.redirect2.me/)
2+
3+
Server that determines your physical location by looking at headers sent to Netlify edge functions.
4+
5+
Try it with: [Netlify](https://netlify-geo.redirect2.me/)
6+
7+
Also see a more detailed [comparison of geolocation providers](https://resolve.rs/ip/geolocation.html)
8+
9+
## How it works
10+
11+
This application is just a simple app that shows various HTTP header values.
12+
13+
## Running it yourself
14+
15+
It is a trivial TypeScript application.
16+
17+
LATER
18+
19+
## Contributions
20+
21+
Contributions are welcome! If you know of any other similar CDNs/services, let me know & I will add them in!
22+
23+
## API
24+
25+
There is a simple JSON/JSONP API that is free for light, non-commercial use. This is such a trivial application that you should run your own copy (or make your own version) for anything serious. Both Netlify has a generous free plan (which is what I'm using).
26+
27+
Send a `callback` parameter to get JSONP instead of JSON.
28+
29+
- [`/api/cfw.json`](https://aws-geo.redirect2.me/api/cfw.json)
30+
31+
## License
32+
33+
[GNU Affero General Public License v3.0](LICENSE.txt)
34+
35+
## Credits
36+
37+
[![Git](https://www.vectorlogo.zone/logos/git-scm/git-scm-ar21.svg)](https://git-scm.com/ "Version control")
38+
[![Github](https://www.vectorlogo.zone/logos/github/github-ar21.svg)](https://github.com/ "Code hosting")
39+
[![Netlify](https://www.vectorlogo.zone/logos/netlify/netlify-ar21.svg)](https://www.netlify.com/ "Hosting and geolocation")
40+
[![NodePing](https://www.vectorlogo.zone/logos/nodeping/nodeping-ar21.svg)](https://nodeping.com?rid=201109281250J5K3P "Uptime monitoring")
41+
[![svgrepo](https://www.vectorlogo.zone/logos/svgrepo/svgrepo-ar21.svg)](https://www.svgrepo.com/svg/185727/map-position "favicon")
42+
[![water.css](https://www.vectorlogo.zone/logos/netlifyapp_watercss/netlifyapp_watercss-ar21.svg)](https://watercss.netlify.app/ "Classless CSS")
43+
44+
- LATER: typescript, npm, nodeping, etc

build.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
set -o nounset
6+
7+
echo "INFO: build starting at $(date -u +%Y-%m-%dT%H:%M:%SZ)"
8+
9+
echo '{}' \
10+
| jq --arg COMMIT $(git rev-parse --short HEAD) '.commit|=$COMMIT' \
11+
| jq --arg LASTMOD $(date -u +%Y-%m-%dT%H:%M:%SZ) '.lastmod|=$LASTMOD' \
12+
| jq --sort-keys . \
13+
> "./build.json"
14+
15+
jekyll build \
16+
--source docs
17+
18+
echo "INFO: build complete at $(date -u +%Y-%m-%dT%H:%M:%SZ)"

docs/favicon.ico

87.9 KB
Binary file not shown.

docs/favicon.svg

Lines changed: 81 additions & 0 deletions
Loading

docs/robots.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# robots.txt for redirect2.me's geolocation servers
3+
#
4+
#
5+
# not much here, but feel free to index it
6+
#
7+
8+
User-Agent: *
9+
Allow: /

netlify.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build]
2+
command = "./build.sh"
3+
publish = "_site/"

netlify/edge-functions/index.mts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type { Config, Context } from "@netlify/edge-functions";
2+
3+
export default async function handler(req: Request, context: Context) {
4+
const html = `<html>
5+
<head>
6+
<meta charset="utf-8">
7+
<title>Netlify Geolocation - Resolve.rs</title>
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
9+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/light.min.css" />
10+
</head>
11+
<body>
12+
<h1>
13+
<img alt="Resolve.rs geolocation logo" src="favicon.svg" style="height:2.2em;vertical-align:middle;" />
14+
Netlify Geolocation
15+
</h1>
16+
<p>
17+
Determine your real (physical) location based on your IP address, powered by Netlify edge functions.
18+
</p>
19+
<p>
20+
Your IP address: ${req.headers.get('x-forwarded-for')}
21+
</p>
22+
<p>
23+
Country: ${context.geo.country?.name} (${context.geo.country?.code})<br/>
24+
Region: ${context.geo.subdivision?.name} (${context.geo.subdivision?.code})<br/>
25+
City: ${context.geo.city}<br/>
26+
Latitude/Longitude: ${context.geo.latitude}, ${context.geo.longitude}<br/>
27+
Time zone: ${context.geo.timezone}<br/>
28+
</p>
29+
<details><summary>Raw Data</summary>
30+
<pre>${JSON.stringify(context.geo, null, 2)}</pre>
31+
</details>
32+
<p>
33+
<a href="https://github.com/redirect2me/cfw-geolocation">How this works</a>, including API details and source code!
34+
</p>
35+
<p>
36+
<a href="https://resolve.rs/">Resolve.rs</a>
37+
has more
38+
<a href="https://resolve.rs/tools.html">diagnostic tools</a>.
39+
including a
40+
<a href="https://resolve.rs/ip/geolocation.html">comparison of different geolocation APIs</a>.
41+
</p>
42+
</body>
43+
</html>`;
44+
return new Response(html, { headers: {
45+
'Cache-Control': 'public',
46+
'Content-Type': 'text/html',
47+
} });
48+
}
49+
50+
export const config: Config = {
51+
path: "/",
52+
};

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "netlify-geolocation",
3+
"version": "1.0.0",
4+
"description": "IP Geolocation via Netlify edge function headers",
5+
"main": "index.js",
6+
"directories": {
7+
"doc": "docs"
8+
},
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"author": "",
13+
"license": "MIT",
14+
"dependencies": {
15+
"@netlify/edge-functions": "^2.3.1"
16+
}
17+
}

run.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
set -o nounset
6+
7+
jekyll build \
8+
--source docs
9+
10+
export BROWSER=none
11+
12+
netlify dev \
13+
--geo=mock \
14+
--port=4000

0 commit comments

Comments
 (0)