chiitiler 1.22.0 → 1.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/source/http.js +2 -1
- package/dist/source/pmtiles.js +5 -1
- package/dist/source/userAgent.d.ts +5 -1
- package/dist/source/userAgent.js +8 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -107,7 +107,7 @@ const png = await getRenderedTileBuffer({
|
|
|
107
107
|
|
|
108
108
|
Available renderers: `getRenderedTileBuffer`, `getRenderedClipBuffer`, `getRenderedCameraBuffer`, and their `*Stream` variants (`Sharp` instances for further piping).
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
chiitiler doesn't override the `User-Agent` on outbound HTTP requests by default, so the runtime's default is used (Node sends `node`). Some tile providers (e.g. OpenStreetMap) require an identifying User-Agent — set one with `setUserAgent('my-app/1.0')` or the `CHIITILER_USER_AGENT` environment variable.
|
|
111
111
|
|
|
112
112
|
## Configuration
|
|
113
113
|
|
|
@@ -119,7 +119,7 @@ All options can be set via CLI flag or environment variable.
|
|
|
119
119
|
| --- | --- | --- |
|
|
120
120
|
| `--port <n>` | `CHIITILER_PORT` | `3000` |
|
|
121
121
|
| `--debug` | `CHIITILER_DEBUG` | `false` |
|
|
122
|
-
| `--user-agent <ua>` | `CHIITILER_USER_AGENT` |
|
|
122
|
+
| `--user-agent <ua>` | `CHIITILER_USER_AGENT` | (none) |
|
|
123
123
|
| — | `CHIITILER_PROCESSES` | `1` (set `0` for all CPUs) |
|
|
124
124
|
|
|
125
125
|
### Cache
|
package/dist/source/http.js
CHANGED
|
@@ -9,8 +9,9 @@ async function getHttpSource(uri, cache = noneCache()) {
|
|
|
9
9
|
return val; // hit
|
|
10
10
|
// miss
|
|
11
11
|
try {
|
|
12
|
+
const userAgent = getUserAgent();
|
|
12
13
|
const res = await fetch(uri, {
|
|
13
|
-
headers: { 'User-Agent':
|
|
14
|
+
headers: userAgent ? { 'User-Agent': userAgent } : undefined,
|
|
14
15
|
});
|
|
15
16
|
if (!res.ok) {
|
|
16
17
|
console.log(`failed to fetch ${uri}`);
|
package/dist/source/pmtiles.js
CHANGED
|
@@ -83,7 +83,11 @@ async function getPmtilesSource(uri, cache = noneCache()) {
|
|
|
83
83
|
if (val !== undefined)
|
|
84
84
|
return val; // hit
|
|
85
85
|
if (pmtiles === undefined) {
|
|
86
|
-
const
|
|
86
|
+
const userAgent = getUserAgent();
|
|
87
|
+
const headers = new Headers();
|
|
88
|
+
if (userAgent)
|
|
89
|
+
headers.set('User-Agent', userAgent);
|
|
90
|
+
const fetchSource = new FetchSource(pmtilesUri, headers);
|
|
87
91
|
pmtiles = new PMTiles(fetchSource);
|
|
88
92
|
pmtilesCache.set(pmtilesUri, pmtiles);
|
|
89
93
|
}
|
|
@@ -3,5 +3,9 @@
|
|
|
3
3
|
* Takes precedence over the CHIITILER_USER_AGENT environment variable.
|
|
4
4
|
*/
|
|
5
5
|
declare function setUserAgent(userAgent: string | undefined): void;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Returns the configured User-Agent, or undefined when none is set (in which
|
|
8
|
+
* case no User-Agent header should be added).
|
|
9
|
+
*/
|
|
10
|
+
declare function getUserAgent(): string | undefined;
|
|
7
11
|
export { getUserAgent, setUserAgent };
|
package/dist/source/userAgent.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// User-Agent for all outbound HTTP requests (http(s):// and pmtiles://http(s)://).
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
2
|
+
// By default we don't override the User-Agent at all (the runtime's default is
|
|
3
|
+
// used). Set one explicitly via --user-agent, CHIITILER_USER_AGENT, or
|
|
4
|
+
// setUserAgent() — e.g. some tile providers (OpenStreetMap) require one.
|
|
5
5
|
let overrideUserAgent;
|
|
6
6
|
/**
|
|
7
7
|
* Override the User-Agent sent with outbound HTTP requests.
|
|
@@ -10,9 +10,11 @@ let overrideUserAgent;
|
|
|
10
10
|
function setUserAgent(userAgent) {
|
|
11
11
|
overrideUserAgent = userAgent;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns the configured User-Agent, or undefined when none is set (in which
|
|
15
|
+
* case no User-Agent header should be added).
|
|
16
|
+
*/
|
|
13
17
|
function getUserAgent() {
|
|
14
|
-
return
|
|
15
|
-
process.env.CHIITILER_USER_AGENT ??
|
|
16
|
-
DEFAULT_USER_AGENT);
|
|
18
|
+
return overrideUserAgent ?? process.env.CHIITILER_USER_AGENT;
|
|
17
19
|
}
|
|
18
20
|
export { getUserAgent, setUserAgent };
|