-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaxmind-geoip-module.html
219 lines (215 loc) · 9.52 KB
/
maxmind-geoip-module.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<html data-navbar="navbar.html">
<head>
<title>MaxMind GeoIP module documentation</title>
<link rel="stylesheet" href="/public/style.css" integrity="sha384-XmYAsTgQ0mGje5sxXJRryYc/mmaL3bnA+Hn9kHkpyRTgdpgM220bOzj5BgWZ41jo" crossorigin="anonymous" />
<script async="" src="/public/highlight.min.js" integrity="sha384-YicwDnP9OMQKl5DfX4/eDA3oUGqPTcuyq0+eFbwv595VqixFKEgoO/T8TxD0tjB8" crossorigin="anonymous"></script>
<script src="/public/browser.js" integrity="sha384-pNXFiUIAMNO/S1fGF4GF3fq8OV5x2fZdicewcpuMG/2EOOJ7+HH3no0GDKTePhCD" crossorigin="anonymous"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="UTF-8" />
<body><a name="top" id="top"></a>
<div class="body-container">
<header>
<h1 id="dashboard">MaxMind GeoIP module documentation</h1>
<section id="navigation" class="navigation">
<menu id="navbar-handle" class="super-navbar" style="display: none">
<li><a href="#" title="Show menu">Show navigation menu</a></li>
</menu>
<ul id="navbar-menu" style="display: block">
<li>
<h2>Dashboard</h2>
<ul>
<li><a href="/dashboard">Documentation</a></li>
<li><a href="/dashboard-configuration">Configuration variables</a></li>
<li><a href="/dashboard-sitemap">Visual sitemap</a></li>
<li><a href="/dashboard-ui">UI index</a></li>
<li><a href="/dashboard-api">API index</a></li>
</ul>
</li>
<li>
<h2>MaxMind GeoIP</h2>
<ul>
<li><a href="/maxmind-geoip-module">Documentation</a></li>
<li><a href="/maxmind-geoip-api">API index</a></li>
</ul>
</li>
<li>
<h2>Organizations</h2>
<ul>
<li><a href="/organizations-module">Documentation</a></li>
<li><a href="/organizations-configuration">Configuration variables</a></li>
<li><a href="/organizations-sitemap">Visual sitemap</a></li>
<li><a href="/organizations-ui">UI index</a></li>
<li><a href="/organizations-api">API index</a></li>
</ul>
</li>
<li>
<h2>Stripe Connect</h2>
<ul>
<li><a href="/stripe-connect-module">Documentation</a></li>
<li><a href="/stripe-connect-configuration">Configuration variables</a></li>
<li><a href="/stripe-connect-sitemap">Visual sitemap</a></li>
<li><a href="/stripe-connect-ui">UI index</a></li>
<li><a href="/stripe-connect-api">API index</a></li>
</ul>
</li>
<li>
<h2>Stripe Subscriptions</h2>
<ul>
<li><a href="/stripe-subscriptions-module">Documentation</a></li>
<li><a href="/stripe-subscriptions-configuration">Configuration variables</a></li>
<li><a href="/stripe-subscriptions-sitemap">Visual sitemap</a></li>
<li><a href="/stripe-subscriptions-ui">UI index</a></li>
<li><a href="/stripe-subscriptions-api">API index</a></li>
</ul>
</li>
<li>
<h2>Example app</h2>
<ul>
<li><a href="/example-web-app">Documentation</a></li>
<li><a href="/example-web-app-sitemap">Visual sitemap</a></li>
<li><a href="/example-web-app-ui">UI index</a></li>
</ul>
</li>
<li>
<h2>Example subscription app</h2>
<ul>
<li><a href="/example-subscription-web-app">Documentation</a></li>
<li><a href="/example-subscription-web-app-sitemap">Visual sitemap</a></li>
<li><a href="/example-subscription-web-app-ui">UI index</a></li>
</ul>
</li>
</ul>
<style>
.reveal,
.reveal ul {
display: block
}
</style>
<script>
var menu = document.getElementById("navbar-menu")
menu.style.display = "none"
var handle = document.getElementById("navbar-handle")
handle.style.display = "block"
handle.onclick = function(e) {
if (menu.style.display === "block") {
menu.style.display = "none"
menu.className = ""
handle.firstElementChild.firstElementChild.innerHTML = "Show navigation menu"
} else {
menu.style.display = "block"
menu.className = "reveal"
handle.firstElementChild.firstElementChild.innerHTML = "Hide navigation menu"
}
}
</script>
</section>
</header>
<div class="section-container">
<section class="full"><a name="content" id="content"></a>
<div class="content">
<h1 id="documentation-for-maxmind-geoip-module">Documentation for Maxmind GeoIP module</h1>
<h4>Index</h4>
<ul>
<li><a href="#maxmind-geoip-module">Introduction</a></li>
<li><a href="#module-contents">Module contents</a></li>
<li><a href="#import-this-module">Import this module</a></li>
<li><a href="#access-the-api">Access the API</a></li>
<li><a href="https://github.com/userdashboard/maxmind-geoip">Github repository</a></li>
<li><a href="https://npmjs.org/userdashboard/maxmind-geoip">NPM package</a></li>
</ul>
<h1 id="introduction">Introduction</h1>
<p>Dashboard bundles everything a web app needs, all the "boilerplate" like signing in and changing passwords, into a parallel server so you can write a much smaller web app.</p>
<p><a href="https://www.maxmind.com/en/home">MaxMind</a> provide a database that converts IP addresses to countries and this module adds API routes for identifying the country by IP and a server handler that will automatically attach a Country object to each HttpRequest using their database. There is much more data in the MaxMind database than is exposed via the API, pull requests are welcome to add more routes to access it.</p>
<h1 id="module-contents">Module contents</h1>
<p>Dashboard modules can add pages and API routes. For more details check the <code data-language="js">sitemap.txt</code> and <code data-language="js">api.txt</code> or <code data-language="js">env.txt</code> also contained in the online documentation.</p>
<table>
<thead>
<tr>
<th>Content type</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Proxy scripts</td>
<td></td>
</tr>
<tr>
<td>Server scripts</td>
<td>Yes</td>
</tr>
<tr>
<td>Content scripts</td>
<td></td>
</tr>
<tr>
<td>User pages</td>
<td></td>
</tr>
<tr>
<td>User API routes</td>
<td>Yes</td>
</tr>
<tr>
<td>Administrator pages</td>
<td></td>
</tr>
<tr>
<td>Administrator API routes</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="import-this-module">Import this module</h2>
<p>Install the module with NPM:</p>
<pre><code data-language="js">$ npm install @userdashboard/maxmind-geoip
</code></pre>
<p>Edit your <code data-language="js">package.json</code> to activate the module:</p>
<pre><code data-language="js">"dashboard": {
"modules": [
"@userdashboard/maxmind-geoip"
]
}
</code></pre>
<h2 id="access-the-api">Access the API</h2>
<p>Dashboard and official modules are completely API-driven and you can access the same APIs on behalf of the user making requests. You perform <code data-language="js">GET</code>, <code data-language="js">POST</code>, <code data-language="js">PATCH</code>, and <code data-language="js">DELETE</code> HTTP requests against the API endpoints to fetch or modify data. This example fetches the user's country information using NodeJS, you can do this with any language:</p>
<pre><code data-language="js">const country = await proxy(`/api/user/maxmind/country?ip=1.2.3.4`, accountid, sessionid)
const proxy = util.promisify((path, accountid, sessionid, callback) => {
const requestOptions = {
host: 'dashboard.example.com',
path: path,
port: '443',
method: 'GET',
headers: {
'x-application-server': 'application.example.com',
'x-application-server-token': process.env.APPLICATION_SERVER_TOKEN
}
}
if (accountid) {
requestOptions.headers['x-accountid'] = accountid
requestOptions.headers['x-sessionid'] = sessionid
}
const proxyRequest = require('https').request(requestOptions, (proxyResponse) => {
let body = ''
proxyResponse.on('data', (chunk) => {
body += chunk
})
return proxyResponse.on('end', () => {
return callback(null, JSON.parse(body))
})
})
proxyRequest.on('error', (error) => {
return callback(error)
})
return proxyRequest.end()
})
}
</code></pre>
</div>
<p><a href="#top">Top of page</a></p>
</section>
</div>
</div>
</body>
</head>
</html>