@basemaps/server 6.24.2 → 6.27.0
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/CHANGELOG.md +29 -0
- package/README.md +12 -0
- package/build/cli.d.ts +2 -1
- package/build/cli.d.ts.map +1 -1
- package/build/cli.js +26 -33
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/server.d.ts +3 -2
- package/build/server.d.ts.map +1 -1
- package/build/server.js +46 -28
- package/package.json +9 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,35 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [6.27.0](https://github.com/linz/basemaps/compare/v6.26.0...v6.27.0) (2022-05-29)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **config:** add configuration parser and bundler ([#2200](https://github.com/linz/basemaps/issues/2200)) ([795e3f2](https://github.com/linz/basemaps/commit/795e3f224ee0b4cd1e66a242d05a1fd5357cae3a))
|
|
12
|
+
* **lambda-cog:** New lambda Cog for import api. ([#2207](https://github.com/linz/basemaps/issues/2207)) ([79f4ae7](https://github.com/linz/basemaps/commit/79f4ae70ea3fc16a37dd575b843a0b60a1365df4))
|
|
13
|
+
* **server:** use a bundled `@basemaps/landing` to serve static assets ([#2202](https://github.com/linz/basemaps/issues/2202)) ([c60f518](https://github.com/linz/basemaps/commit/c60f518893fe037a03f8bfd489c84d8427481678))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# [6.26.0](https://github.com/linz/basemaps/compare/v6.25.0...v6.26.0) (2022-05-12)
|
|
20
|
+
|
|
21
|
+
**Note:** Version bump only for package @basemaps/server
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# [6.25.0](https://github.com/linz/basemaps/compare/v6.24.2...v6.25.0) (2022-05-11)
|
|
28
|
+
|
|
29
|
+
**Note:** Version bump only for package @basemaps/server
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
6
35
|
## [6.24.2](https://github.com/linz/basemaps/compare/v6.24.1...v6.24.2) (2022-04-20)
|
|
7
36
|
|
|
8
37
|
|
package/README.md
CHANGED
|
@@ -33,3 +33,15 @@ For example given a structure where there are two folders full of tiffs
|
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
running `basemaps-server --config /images` will create two tile sets one for each folder `gebco_2021...` and `geographx_nz_t...` and then also create a combined layer in the order the tiffs are found.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## Developing
|
|
39
|
+
|
|
40
|
+
When running the `@basemaps/server` in development mode, ensure `@basemaps/landing` page has been bundled
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
cd packages/landing
|
|
44
|
+
yarn bundle
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This will package all the static assets into `landing/dist` and will be served from `http://localhost:3000`
|
package/build/cli.d.ts
CHANGED
|
@@ -6,9 +6,10 @@ export declare class BasemapsServerCommand extends Command {
|
|
|
6
6
|
port: import("@oclif/parser/lib/flags").IOptionFlag<number>;
|
|
7
7
|
dynamo: flags.IOptionFlag<string | undefined>;
|
|
8
8
|
config: flags.IOptionFlag<string | undefined>;
|
|
9
|
+
files: flags.IOptionFlag<string | undefined>;
|
|
9
10
|
};
|
|
10
11
|
static args: never[];
|
|
11
|
-
|
|
12
|
+
loadTiffs(tiffPath: string, serverUrl: string): Promise<void>;
|
|
12
13
|
run(): Promise<void>;
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=cli.d.ts.map
|
package/build/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAkBhD,qBAAa,qBAAsB,SAAQ,OAAO;IAChD,MAAM,CAAC,WAAW,SAAuD;IACzE,MAAM,CAAC,KAAK;;;;;;MAMV;IAEF,MAAM,CAAC,IAAI,UAAM;IAEX,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B7D,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAoC3B"}
|
package/build/cli.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import { ConfigPrefix, ConfigProviderDynamo, ConfigProviderMemory, parseRgba } from '@basemaps/config';
|
|
1
|
+
import { ConfigJson, ConfigProviderDynamo, ConfigProviderMemory } from '@basemaps/config';
|
|
3
2
|
import { TileSetLocal } from '@basemaps/lambda-tiler/build/cli/tile.set.local.js';
|
|
4
3
|
import { TileSets } from '@basemaps/lambda-tiler/build/tile.set.cache.js';
|
|
5
|
-
import { Config, Env, LogConfig } from '@basemaps/shared';
|
|
6
|
-
import { fsa } from '@linzjs/s3fs';
|
|
4
|
+
import { Config, Env, fsa, LogConfig } from '@basemaps/shared';
|
|
7
5
|
import { Command, flags } from '@oclif/command';
|
|
8
6
|
import { basename, dirname } from 'path';
|
|
9
|
-
import {
|
|
7
|
+
import { createServer } from './server.js';
|
|
10
8
|
const logger = LogConfig.get();
|
|
11
9
|
const BaseProvider = {
|
|
12
10
|
id: 'pv_linz',
|
|
@@ -20,11 +18,11 @@ const BaseProvider = {
|
|
|
20
18
|
},
|
|
21
19
|
};
|
|
22
20
|
export class BasemapsServerCommand extends Command {
|
|
23
|
-
async
|
|
21
|
+
async loadTiffs(tiffPath, serverUrl) {
|
|
24
22
|
const config = new ConfigProviderMemory();
|
|
25
23
|
Config.setConfigProvider(config);
|
|
26
24
|
const tifSets = new Map();
|
|
27
|
-
for await (const file of fsa.
|
|
25
|
+
for await (const file of fsa.details(tiffPath)) {
|
|
28
26
|
const lowerPath = file.path.toLowerCase();
|
|
29
27
|
if (lowerPath.endsWith('.tiff') || lowerPath.endsWith('.tif')) {
|
|
30
28
|
const tiffPath = dirname(file.path);
|
|
@@ -40,27 +38,6 @@ export class BasemapsServerCommand extends Command {
|
|
|
40
38
|
if (!config.objects.has('pv_linz'))
|
|
41
39
|
config.put(BaseProvider);
|
|
42
40
|
}
|
|
43
|
-
if (!lowerPath.endsWith('.json'))
|
|
44
|
-
continue;
|
|
45
|
-
logger.trace({ path: file.path, size: file.size }, 'Config:Load');
|
|
46
|
-
const jsonData = await fsa.read(file.path).then((c) => JSON.parse(c.toString()));
|
|
47
|
-
if (jsonData.id == null) {
|
|
48
|
-
logger.warn({ path: file.path }, 'Config:Invalid Missing "id"');
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
// Last modified now, make sure its considered fresh
|
|
52
|
-
jsonData.updatedAt = Date.now();
|
|
53
|
-
// TODO we should really use something like zod to validate this
|
|
54
|
-
config.put(jsonData);
|
|
55
|
-
if (!Config.TileSet.is(jsonData) || !Config.isTileSetRaster(jsonData))
|
|
56
|
-
continue;
|
|
57
|
-
if (typeof jsonData.background === 'string')
|
|
58
|
-
jsonData.background = parseRgba(jsonData.background);
|
|
59
|
-
const tileSet = Config.unprefix(ConfigPrefix.TileSet, jsonData.id);
|
|
60
|
-
if (jsonData.name == null)
|
|
61
|
-
jsonData.name = tileSet;
|
|
62
|
-
const wmtsUrl = `${serverUrl}/v1/tiles/${tileSet}/WMTSCapabilities.xml`;
|
|
63
|
-
logger.info({ tileSetId: jsonData.id, wmtsUrl }, 'TileSet:Loaded');
|
|
64
41
|
}
|
|
65
42
|
}
|
|
66
43
|
async run() {
|
|
@@ -70,19 +47,34 @@ export class BasemapsServerCommand extends Command {
|
|
|
70
47
|
logger.level = 'debug';
|
|
71
48
|
const ServerUrl = `http://localhost:${flags.port}`;
|
|
72
49
|
if (flags.config != null) {
|
|
73
|
-
|
|
74
|
-
|
|
50
|
+
// Load configuration from a collection of JSON files
|
|
51
|
+
logger.info({ path: flags.config, mode: 'config' }, 'Starting Server');
|
|
52
|
+
if (flags.config.endsWith('.json')) {
|
|
53
|
+
const configJson = await fsa.read(flags.config);
|
|
54
|
+
const mem = ConfigProviderMemory.fromJson(JSON.parse(configJson.toString()));
|
|
55
|
+
Config.setConfigProvider(mem);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const cj = await ConfigJson.fromPath(flags.config, logger);
|
|
59
|
+
Config.setConfigProvider(cj.mem);
|
|
60
|
+
}
|
|
75
61
|
}
|
|
76
62
|
else if (flags.dynamo != null) {
|
|
77
|
-
|
|
63
|
+
// Load configuration from a dynamodb table
|
|
64
|
+
logger.info({ dynamo: flags.dynamo, mode: 'dynamo' }, 'Starting Server');
|
|
78
65
|
Config.setConfigProvider(new ConfigProviderDynamo(flags.dynamo));
|
|
79
66
|
}
|
|
67
|
+
else if (flags.files != null) {
|
|
68
|
+
// Generate configuration form a collection of tiff files
|
|
69
|
+
logger.info({ path: flags.files, mode: 'files' }, 'Starting Server');
|
|
70
|
+
await this.loadTiffs(flags.files, ServerUrl);
|
|
71
|
+
}
|
|
80
72
|
else {
|
|
81
|
-
throw new Error('Either a
|
|
73
|
+
throw new Error('Either a --config, --tiff or --dynamodb must be supplied');
|
|
82
74
|
}
|
|
83
75
|
// Force a default url base so WMTS requests know their relative url
|
|
84
76
|
process.env[Env.PublicUrlBase] = (_a = process.env[Env.PublicUrlBase]) !== null && _a !== void 0 ? _a : `http://localhost:${flags.port}`;
|
|
85
|
-
|
|
77
|
+
createServer(logger).listen(flags.port, () => {
|
|
86
78
|
logger.info({ url: ServerUrl }, 'ServerStarted');
|
|
87
79
|
});
|
|
88
80
|
}
|
|
@@ -93,5 +85,6 @@ BasemapsServerCommand.flags = {
|
|
|
93
85
|
port: flags.integer({ default: 5000 }),
|
|
94
86
|
dynamo: flags.string({ description: 'Dynamodb table', required: false }),
|
|
95
87
|
config: flags.string({ description: 'Configuration path', required: false }),
|
|
88
|
+
files: flags.string({ description: 'Use folders of tiffs as the configuration', required: false }),
|
|
96
89
|
};
|
|
97
90
|
BasemapsServerCommand.args = [];
|
package/build/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createServer } from './server.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createServer } from './server.js';
|
package/build/server.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { LogType } from '@basemaps/shared';
|
|
2
|
+
import { FastifyInstance } from 'fastify';
|
|
3
|
+
export declare function createServer(logger: LogType): FastifyInstance;
|
|
3
4
|
//# sourceMappingURL=server.d.ts.map
|
package/build/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAI3C,OAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAcnD,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,eAAe,CAyC7D"}
|
package/build/server.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { handler } from '@basemaps/lambda-tiler';
|
|
2
|
+
import fastifyStatic from '@fastify/static';
|
|
2
3
|
import { lf } from '@linzjs/lambda';
|
|
3
4
|
import fastify from 'fastify';
|
|
5
|
+
import { createRequire } from 'module';
|
|
6
|
+
import path from 'path';
|
|
4
7
|
import ulid from 'ulid';
|
|
5
|
-
|
|
8
|
+
import { URL } from 'url';
|
|
6
9
|
function isAlbResult(r) {
|
|
7
10
|
if (typeof r !== 'object')
|
|
8
11
|
return false;
|
|
@@ -11,31 +14,46 @@ function isAlbResult(r) {
|
|
|
11
14
|
return 'statusCode' in r;
|
|
12
15
|
}
|
|
13
16
|
const instanceId = ulid.ulid();
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
17
|
+
export function createServer(logger) {
|
|
18
|
+
const BasemapsServer = fastify();
|
|
19
|
+
const require = createRequire(import.meta.url);
|
|
20
|
+
const landingLocation = require.resolve('@basemaps/landing');
|
|
21
|
+
if (landingLocation == null) {
|
|
22
|
+
logger.warn('Server:Landing:Failed');
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const root = path.join(path.dirname(landingLocation), '..', 'dist');
|
|
26
|
+
logger.info({ path: root }, 'Server:Landing');
|
|
27
|
+
BasemapsServer.register(fastifyStatic, { root });
|
|
28
|
+
}
|
|
29
|
+
BasemapsServer.get('/v1/*', async (req, res) => {
|
|
30
|
+
const url = new URL(`${req.protocol}://${req.hostname}${req.url}`);
|
|
31
|
+
const event = {
|
|
32
|
+
httpMethod: 'GET',
|
|
33
|
+
requestContext: { elb: { targetGroupArn: 'arn:fake' } },
|
|
34
|
+
path: url.pathname,
|
|
35
|
+
headers: req.headers,
|
|
36
|
+
queryStringParameters: req.query,
|
|
37
|
+
body: null,
|
|
38
|
+
isBase64Encoded: false,
|
|
39
|
+
};
|
|
40
|
+
if (req.query.api == null)
|
|
41
|
+
req.query.api = 'c' + instanceId;
|
|
42
|
+
handler(event, {}, (err, r) => {
|
|
43
|
+
var _a;
|
|
44
|
+
if (err || !isAlbResult(r)) {
|
|
45
|
+
lf.Logger.fatal({ err }, 'RequestFailed');
|
|
46
|
+
res.send(err);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
res.status(r.statusCode);
|
|
50
|
+
for (const [key, value] of Object.entries((_a = r.headers) !== null && _a !== void 0 ? _a : {}))
|
|
51
|
+
res.header(key, String(value));
|
|
52
|
+
if (r.body)
|
|
53
|
+
res.send(Buffer.from(r.body, r.isBase64Encoded ? 'base64' : 'utf8'));
|
|
54
|
+
else
|
|
55
|
+
res.send('Not found');
|
|
56
|
+
});
|
|
40
57
|
});
|
|
41
|
-
|
|
58
|
+
return BasemapsServer;
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basemaps/server",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.27.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/linz/basemaps.git",
|
|
@@ -32,14 +32,16 @@
|
|
|
32
32
|
"bin/"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@basemaps/config": "^6.
|
|
36
|
-
"@basemaps/geo": "^6.
|
|
37
|
-
"@basemaps/lambda-tiler": "^6.
|
|
38
|
-
"@basemaps/
|
|
39
|
-
"@
|
|
35
|
+
"@basemaps/config": "^6.27.0",
|
|
36
|
+
"@basemaps/geo": "^6.26.0",
|
|
37
|
+
"@basemaps/lambda-tiler": "^6.27.0",
|
|
38
|
+
"@basemaps/landing": "^6.27.0",
|
|
39
|
+
"@basemaps/shared": "^6.27.0",
|
|
40
|
+
"@fastify/static": "^5.0.2",
|
|
41
|
+
"@linzjs/lambda": "^3.0.1",
|
|
40
42
|
"@oclif/command": "^1.8.0",
|
|
41
43
|
"fastify": "^3.27.4",
|
|
42
44
|
"pretty-json-log": "^1.0.0"
|
|
43
45
|
},
|
|
44
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "c6aa61c20503cbc7f04cf31927f4e2b95aed34cb"
|
|
45
47
|
}
|