@basemaps/server 6.26.0 → 6.28.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/CHANGELOG.md +35 -0
- package/README.md +47 -3
- package/build/cli.d.ts +10 -11
- package/build/cli.d.ts.map +1 -1
- package/build/cli.js +79 -54
- 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 +54 -28
- package/package.json +28 -10
- package/bin/basemaps-server.js +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,41 @@
|
|
|
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.28.1](https://github.com/linz/basemaps/compare/v6.28.0...v6.28.1) (2022-06-07)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @basemaps/server
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [6.28.0](https://github.com/linz/basemaps/compare/v6.27.0...v6.28.0) (2022-06-06)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **docker:** add a container of basemaps-server and basemaps-landing ([#2225](https://github.com/linz/basemaps/issues/2225)) ([13f8144](https://github.com/linz/basemaps/commit/13f814446de0b2896e0ccca620d4b0a017380c14))
|
|
20
|
+
* **server:** bundle basemaps-server cli so its easier to install ([#2218](https://github.com/linz/basemaps/issues/2218)) ([8457b66](https://github.com/linz/basemaps/commit/8457b66be6d0f54decf43b515bb78853cefbc8ed))
|
|
21
|
+
* **server:** provide a better error when loading configuration bundles ([#2222](https://github.com/linz/basemaps/issues/2222)) ([8318192](https://github.com/linz/basemaps/commit/83181920c8a9e061babd38a8ffd0dec93830dced))
|
|
22
|
+
* **sprites:** create sprites using sharp ([#2235](https://github.com/linz/basemaps/issues/2235)) ([e7b6a9e](https://github.com/linz/basemaps/commit/e7b6a9e9c95359dc866b40e7a6988837a71d9d96))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# [6.27.0](https://github.com/linz/basemaps/compare/v6.26.0...v6.27.0) (2022-05-29)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Features
|
|
32
|
+
|
|
33
|
+
* **config:** add configuration parser and bundler ([#2200](https://github.com/linz/basemaps/issues/2200)) ([795e3f2](https://github.com/linz/basemaps/commit/795e3f224ee0b4cd1e66a242d05a1fd5357cae3a))
|
|
34
|
+
* **lambda-cog:** New lambda Cog for import api. ([#2207](https://github.com/linz/basemaps/issues/2207)) ([79f4ae7](https://github.com/linz/basemaps/commit/79f4ae70ea3fc16a37dd575b843a0b60a1365df4))
|
|
35
|
+
* **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))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
6
41
|
# [6.26.0](https://github.com/linz/basemaps/compare/v6.25.0...v6.26.0) (2022-05-12)
|
|
7
42
|
|
|
8
43
|
**Note:** Version bump only for package @basemaps/server
|
package/README.md
CHANGED
|
@@ -2,14 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
WMTS/XYZ Tile server command line interface.
|
|
4
4
|
|
|
5
|
-
This wraps the @basemaps/
|
|
5
|
+
This wraps the @basemaps/tiler into a standalone express http server.
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
|
+
Basemaps server expects a folder tree full of configuration, with multiple tilesets and styles configuration files.
|
|
8
9
|
|
|
10
|
+
```bash
|
|
11
|
+
basemaps-server --config path/to/config/
|
|
9
12
|
```
|
|
10
|
-
|
|
13
|
+
|
|
14
|
+
### Usage docker
|
|
15
|
+
|
|
16
|
+
The server is also published as a docker container
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
docker run -it \
|
|
20
|
+
--volume $PWD/config:/config \
|
|
21
|
+
--volume $PWD/tiffs:$PWD/tiffs \
|
|
22
|
+
-p 5000:5000 \
|
|
23
|
+
ghcr.io/linz/basemaps-server:v6.28.0 --config /config
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Where `${PWD}/config` contains all the configuration and `${PWD}/tiffs` is all the relevant tiff files
|
|
27
|
+
|
|
28
|
+
### Bundled configuration
|
|
29
|
+
|
|
30
|
+
Basemaps server can also be configured with a single configuration bundle file, which can be created from a configuration folder
|
|
31
|
+
|
|
32
|
+
By bundling the configuration the startup time is greatly reduced as each individual tiff file does not have to be scanned for dimensions, it does mean that new tiffs will not be picked up until a new bundle is created.
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
basemaps-server --config path/to/config/ --bundle config.bundle.json
|
|
36
|
+
basemaps-server --config config.bundle.json
|
|
11
37
|
```
|
|
12
38
|
|
|
39
|
+
|
|
40
|
+
### Usage with LINZ imagery
|
|
13
41
|
Usage with basemaps config, you will need access to basemaps' imagery cache
|
|
14
42
|
|
|
15
43
|
please contact basemaps@linz.govt.nz if you need access.
|
|
@@ -20,6 +48,8 @@ basemaps-server --config basemaps-config/config
|
|
|
20
48
|
```
|
|
21
49
|
|
|
22
50
|
|
|
51
|
+
|
|
52
|
+
|
|
23
53
|
### Direct TIFF access
|
|
24
54
|
|
|
25
55
|
If you have a folder of tiffs the basemaps-server can index the folder and create tiles from
|
|
@@ -32,4 +62,18 @@ For example given a structure where there are two folders full of tiffs
|
|
|
32
62
|
/images/10_geographx_nz_texture_shade_2012_8-0m_01FHRPYJ5FV1XAARZAC4T4K6MC/*.tiff
|
|
33
63
|
```
|
|
34
64
|
|
|
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.
|
|
65
|
+
running `basemaps-server --config /images --no-config` 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.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## Developing
|
|
69
|
+
|
|
70
|
+
When running the `@basemaps/server` in development mode, ensure `@basemaps/landing` page has been bundled
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
yarn
|
|
74
|
+
yarn build
|
|
75
|
+
|
|
76
|
+
npx lerna run bundle --stream # Bundle everything
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
This will package all the static assets into `landing/dist` and will be served from `http://localhost:5000`
|
package/build/cli.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
1
|
+
import { LogType } from '@basemaps/shared';
|
|
2
|
+
import { BaseCommandLine } from '@basemaps/shared/build/cli/base.js';
|
|
3
|
+
export declare class BasemapsServerCommand extends BaseCommandLine {
|
|
4
|
+
config: import("@rushstack/ts-command-line").CommandLineStringParameter;
|
|
5
|
+
ignoreConfig: import("@rushstack/ts-command-line").CommandLineFlagParameter;
|
|
6
|
+
bundle: import("@rushstack/ts-command-line").CommandLineStringParameter;
|
|
7
|
+
port: import("@rushstack/ts-command-line").CommandLineIntegerParameter;
|
|
8
|
+
constructor();
|
|
10
9
|
static args: never[];
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
loadTiffs(tiffPath: string, serverUrl: string, logger: LogType): Promise<void>;
|
|
11
|
+
onExecute(): Promise<void>;
|
|
13
12
|
}
|
|
14
13
|
//# 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":"AAGA,OAAO,EAAsC,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAW,MAAM,oCAAoC,CAAC;AAoB9E,qBAAa,qBAAsB,SAAQ,eAAe;IACxD,MAAM,kEAIH;IACH,YAAY,gEAGT;IACH,MAAM,kEAIH;IACH,IAAI,mEAKD;;IASH,MAAM,CAAC,IAAI,UAAM;IAEX,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B9E,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAkDjC"}
|
package/build/cli.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
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 {
|
|
7
|
-
import { Command, flags } from '@oclif/command';
|
|
4
|
+
import { Config, Const, Env, fsa, LogConfig } from '@basemaps/shared';
|
|
5
|
+
import { BaseCommandLine, CliInfo } from '@basemaps/shared/build/cli/base.js';
|
|
8
6
|
import { basename, dirname } from 'path';
|
|
9
|
-
import {
|
|
10
|
-
|
|
7
|
+
import { createServer } from './server.js';
|
|
8
|
+
CliInfo.package = 'basemaps/server';
|
|
11
9
|
const BaseProvider = {
|
|
12
10
|
id: 'pv_linz',
|
|
13
11
|
version: 1,
|
|
@@ -19,12 +17,39 @@ const BaseProvider = {
|
|
|
19
17
|
},
|
|
20
18
|
},
|
|
21
19
|
};
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const DefaultPort = 5000;
|
|
21
|
+
export class BasemapsServerCommand extends BaseCommandLine {
|
|
22
|
+
constructor() {
|
|
23
|
+
super({
|
|
24
|
+
toolFilename: 'bms',
|
|
25
|
+
toolDescription: 'Create a WMTS/XYZ Tile server from basemaps config',
|
|
26
|
+
});
|
|
27
|
+
this.config = this.defineStringParameter({
|
|
28
|
+
argumentName: 'CONFIG',
|
|
29
|
+
parameterLongName: '--config',
|
|
30
|
+
description: 'Configuration source to use',
|
|
31
|
+
});
|
|
32
|
+
this.ignoreConfig = this.defineFlagParameter({
|
|
33
|
+
parameterLongName: '--no-config',
|
|
34
|
+
description: 'Assume no config and just load tiffs from the configuration path',
|
|
35
|
+
});
|
|
36
|
+
this.bundle = this.defineStringParameter({
|
|
37
|
+
argumentName: 'BUNDLE',
|
|
38
|
+
parameterLongName: '--bundle',
|
|
39
|
+
description: 'Compile the configuration into a bundle and output path',
|
|
40
|
+
});
|
|
41
|
+
this.port = this.defineIntegerParameter({
|
|
42
|
+
argumentName: 'PORT',
|
|
43
|
+
parameterLongName: '--port',
|
|
44
|
+
description: 'port to use',
|
|
45
|
+
defaultValue: DefaultPort,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async loadTiffs(tiffPath, serverUrl, logger) {
|
|
24
49
|
const config = new ConfigProviderMemory();
|
|
25
50
|
Config.setConfigProvider(config);
|
|
26
51
|
const tifSets = new Map();
|
|
27
|
-
for await (const file of fsa.
|
|
52
|
+
for await (const file of fsa.details(tiffPath)) {
|
|
28
53
|
const lowerPath = file.path.toLowerCase();
|
|
29
54
|
if (lowerPath.endsWith('.tiff') || lowerPath.endsWith('.tif')) {
|
|
30
55
|
const tiffPath = dirname(file.path);
|
|
@@ -40,58 +65,58 @@ export class BasemapsServerCommand extends Command {
|
|
|
40
65
|
if (!config.objects.has('pv_linz'))
|
|
41
66
|
config.put(BaseProvider);
|
|
42
67
|
}
|
|
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
68
|
}
|
|
65
69
|
}
|
|
66
|
-
async
|
|
67
|
-
var _a;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
async onExecute() {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
await super.onExecute();
|
|
73
|
+
const logger = LogConfig.get();
|
|
74
|
+
logger.level = 'debug';
|
|
75
|
+
const config = (_a = this.config.value) !== null && _a !== void 0 ? _a : 'dynamodb://' + Const.TileMetadata.TableName;
|
|
76
|
+
const port = this.port.value;
|
|
77
|
+
const ServerUrl = (_b = Env.get(Env.PublicUrlBase)) !== null && _b !== void 0 ? _b : `http://localhost:${port}`;
|
|
78
|
+
// Force a default url base so WMTS requests know their relative url
|
|
79
|
+
process.env[Env.PublicUrlBase] = ServerUrl;
|
|
80
|
+
if (config.startsWith('dynamodb://')) {
|
|
81
|
+
// Load config from dynamodb table
|
|
82
|
+
const table = config.slice('dynamodb://'.length);
|
|
83
|
+
logger.info({ path: config, table, mode: 'dynamo' }, 'Starting Server');
|
|
84
|
+
Config.setConfigProvider(new ConfigProviderDynamo(table));
|
|
85
|
+
}
|
|
86
|
+
else if (config.endsWith('.json')) {
|
|
87
|
+
// Bundled config
|
|
88
|
+
logger.info({ path: config, mode: 'config' }, 'Starting Server');
|
|
89
|
+
const configJson = await fsa.read(config);
|
|
90
|
+
const mem = ConfigProviderMemory.fromJson(JSON.parse(configJson.toString()));
|
|
91
|
+
Config.setConfigProvider(mem);
|
|
75
92
|
}
|
|
76
|
-
else if (
|
|
77
|
-
|
|
78
|
-
|
|
93
|
+
else if (this.ignoreConfig.value) {
|
|
94
|
+
// Load config directly from tiff files
|
|
95
|
+
logger.info({ path: config, mode: 'tiffs' }, 'Starting Server');
|
|
96
|
+
await this.loadTiffs(config, ServerUrl, logger);
|
|
79
97
|
}
|
|
80
98
|
else {
|
|
81
|
-
|
|
99
|
+
const mem = await ConfigJson.fromPath(config, logger);
|
|
100
|
+
const bundlePath = this.bundle.value;
|
|
101
|
+
if (bundlePath) {
|
|
102
|
+
await fsa.writeJson(bundlePath, mem.toJson());
|
|
103
|
+
logger.info({ path: bundlePath }, 'ConfigBundled');
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
// Assume the folder is a collection of config files
|
|
107
|
+
logger.info({ path: config, mode: 'config' }, 'Starting Server');
|
|
108
|
+
mem.createVirtualTileSets();
|
|
109
|
+
Config.setConfigProvider(mem);
|
|
82
110
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
111
|
+
if (this.bundle.value != null) {
|
|
112
|
+
throw new Error('--bundle path provided without providing a configuration path');
|
|
113
|
+
}
|
|
114
|
+
createServer(logger).listen(port !== null && port !== void 0 ? port : DefaultPort, '0.0.0.0', () => {
|
|
86
115
|
logger.info({ url: ServerUrl }, 'ServerStarted');
|
|
87
116
|
});
|
|
88
117
|
}
|
|
89
118
|
}
|
|
90
|
-
BasemapsServerCommand.description = 'Create a WMTS/XYZ Tile server for basemaps config';
|
|
91
|
-
BasemapsServerCommand.flags = {
|
|
92
|
-
verbose: flags.boolean(),
|
|
93
|
-
port: flags.integer({ default: 5000 }),
|
|
94
|
-
dynamo: flags.string({ description: 'Dynamodb table', required: false }),
|
|
95
|
-
config: flags.string({ description: 'Configuration path', required: false }),
|
|
96
|
-
};
|
|
97
119
|
BasemapsServerCommand.args = [];
|
|
120
|
+
new BasemapsServerCommand().executeWithoutErrorHandling().catch((c) => {
|
|
121
|
+
console.error(c);
|
|
122
|
+
});
|
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;AAuBnD,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,eAAe,CAwC7D"}
|
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,54 @@ function isAlbResult(r) {
|
|
|
11
14
|
return 'statusCode' in r;
|
|
12
15
|
}
|
|
13
16
|
const instanceId = ulid.ulid();
|
|
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
|
-
|
|
17
|
+
function getLandingLocation() {
|
|
18
|
+
if (typeof require !== 'undefined' && typeof require.resolve === 'function') {
|
|
19
|
+
return require.resolve('@basemaps/landing/dist');
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
return require.resolve('@basemaps/landing/dist');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function createServer(logger) {
|
|
27
|
+
const BasemapsServer = fastify();
|
|
28
|
+
const landingLocation = getLandingLocation();
|
|
29
|
+
if (landingLocation == null) {
|
|
30
|
+
logger.warn('Server:Landing:Failed');
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const root = path.join(path.dirname(landingLocation), '..', 'dist');
|
|
34
|
+
logger.info({ path: root }, 'Server:Landing');
|
|
35
|
+
BasemapsServer.register(fastifyStatic, { root });
|
|
36
|
+
}
|
|
37
|
+
BasemapsServer.get('/v1/*', async (req, res) => {
|
|
38
|
+
const url = new URL(`${req.protocol}://${req.hostname}${req.url}`);
|
|
39
|
+
const event = {
|
|
40
|
+
httpMethod: 'GET',
|
|
41
|
+
requestContext: { elb: { targetGroupArn: 'arn:fake' } },
|
|
42
|
+
path: url.pathname,
|
|
43
|
+
headers: req.headers,
|
|
44
|
+
queryStringParameters: req.query,
|
|
45
|
+
body: null,
|
|
46
|
+
isBase64Encoded: false,
|
|
47
|
+
};
|
|
48
|
+
if (req.query.api == null)
|
|
49
|
+
req.query.api = 'c' + instanceId;
|
|
50
|
+
handler(event, {}, (err, r) => {
|
|
51
|
+
var _a;
|
|
52
|
+
if (err || !isAlbResult(r)) {
|
|
53
|
+
lf.Logger.fatal({ err }, 'RequestFailed');
|
|
54
|
+
res.send(err);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
res.status(r.statusCode);
|
|
58
|
+
for (const [key, value] of Object.entries((_a = r.headers) !== null && _a !== void 0 ? _a : {}))
|
|
59
|
+
res.header(key, String(value));
|
|
60
|
+
if (r.body)
|
|
61
|
+
res.send(Buffer.from(r.body, r.isBase64Encoded ? 'base64' : 'utf8'));
|
|
62
|
+
else
|
|
63
|
+
res.send('Not found');
|
|
64
|
+
});
|
|
40
65
|
});
|
|
41
|
-
|
|
66
|
+
return BasemapsServer;
|
|
67
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basemaps/server",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.28.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/linz/basemaps.git",
|
|
@@ -19,27 +19,45 @@
|
|
|
19
19
|
"main": "./build/index.js",
|
|
20
20
|
"types": "./build/index.d.ts",
|
|
21
21
|
"scripts": {
|
|
22
|
-
"test": "ospec --globs 'build/**/*.test.js'"
|
|
22
|
+
"test": "ospec --globs 'build/**/*.test.js'",
|
|
23
|
+
"bundle": "../../scripts/bundle.js package.json"
|
|
23
24
|
},
|
|
24
25
|
"publishConfig": {
|
|
25
26
|
"access": "public"
|
|
26
27
|
},
|
|
27
28
|
"bin": {
|
|
28
|
-
"basemaps-server": "./bin/basemaps-server.
|
|
29
|
+
"basemaps-server": "./bin/basemaps-server.cjs"
|
|
29
30
|
},
|
|
31
|
+
"bundle": [
|
|
32
|
+
{
|
|
33
|
+
"entry": "src/cli.ts",
|
|
34
|
+
"outfile": "bin/basemaps-server.cjs",
|
|
35
|
+
"executable": true,
|
|
36
|
+
"external": [
|
|
37
|
+
"pino-pretty",
|
|
38
|
+
"sharp"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
],
|
|
30
42
|
"files": [
|
|
31
43
|
"build/",
|
|
32
44
|
"bin/"
|
|
33
45
|
],
|
|
46
|
+
"optionalDependencies": {
|
|
47
|
+
"@basemaps/landing": "^6.28.1"
|
|
48
|
+
},
|
|
34
49
|
"dependencies": {
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"@basemaps/
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
50
|
+
"sharp": "^0.30.2"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@basemaps/config": "^6.28.1",
|
|
54
|
+
"@basemaps/geo": "^6.28.1",
|
|
55
|
+
"@basemaps/lambda-tiler": "^6.28.1",
|
|
56
|
+
"@basemaps/landing": "^6.27.0",
|
|
57
|
+
"@basemaps/shared": "^6.28.1",
|
|
58
|
+
"@fastify/static": "^5.0.2",
|
|
41
59
|
"fastify": "^3.27.4",
|
|
42
60
|
"pretty-json-log": "^1.0.0"
|
|
43
61
|
},
|
|
44
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "f387e0365bcfc7391fd8d0665195b246c93532cf"
|
|
45
63
|
}
|
package/bin/basemaps-server.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
if (process.env.AWS_REGION == null) process.env.AWS_REGION = process.env.AWS_DEFAULT_REGION;
|
|
4
|
-
|
|
5
|
-
import { BasemapsServerCommand } from '../build/cli.js';
|
|
6
|
-
import Errors from '@oclif/errors/handle.js';
|
|
7
|
-
|
|
8
|
-
BasemapsServerCommand.run(void 0, import.meta.url).catch((error) => {
|
|
9
|
-
if (error.oclif) return Errors(error);
|
|
10
|
-
console.log(error);
|
|
11
|
-
});
|