@basemaps/server 6.10.0 → 6.15.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 CHANGED
@@ -3,6 +3,42 @@
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.15.0](https://github.com/linz/basemaps/compare/v6.14.2...v6.15.0) (2021-11-28)
7
+
8
+ **Note:** Version bump only for package @basemaps/server
9
+
10
+
11
+
12
+
13
+
14
+ ## [6.12.1](https://github.com/linz/basemaps/compare/v6.12.0...v6.12.1) (2021-10-19)
15
+
16
+ **Note:** Version bump only for package @basemaps/server
17
+
18
+
19
+
20
+
21
+
22
+ # [6.12.0](https://github.com/linz/basemaps/compare/v6.11.0...v6.12.0) (2021-10-05)
23
+
24
+ **Note:** Version bump only for package @basemaps/server
25
+
26
+
27
+
28
+
29
+
30
+ # [6.11.0](https://github.com/linz/basemaps/compare/v6.10.1...v6.11.0) (2021-10-03)
31
+
32
+
33
+ ### Features
34
+
35
+ * **server:** add ability to serve a folder full of tiffs ([#1889](https://github.com/linz/basemaps/issues/1889)) ([adefde1](https://github.com/linz/basemaps/commit/adefde176ce03db5c6c978d8b85a11fc7cd15693))
36
+ * **server:** use the lambda handler directly ([#1870](https://github.com/linz/basemaps/issues/1870)) ([408ff56](https://github.com/linz/basemaps/commit/408ff5654cc04aae35d05eb5bbc47a51f99ec5b2))
37
+
38
+
39
+
40
+
41
+
6
42
  # [6.10.0](https://github.com/linz/basemaps/compare/v6.9.1...v6.10.0) (2021-09-22)
7
43
 
8
44
 
@@ -2,7 +2,8 @@
2
2
 
3
3
  import { BasemapsServerCommand } from '../build/cli.js';
4
4
  import Errors from '@oclif/errors/handle.js';
5
- BasemapsServerCommand.run().catch((error) => {
5
+
6
+ BasemapsServerCommand.run(void 0, import.meta.url).catch((error) => {
6
7
  if (error.oclif) return Errors(error);
7
8
  console.log(error);
8
9
  });
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAS,MAAM,gBAAgB,CAAC;AAShD,qBAAa,qBAAsB,SAAQ,OAAO;IAChD,MAAM,CAAC,WAAW,SAAuD;IACzE,MAAM,CAAC,KAAK;;;MAAwE;IAEpF,MAAM,CAAC,IAAI;;;QAA4C;IAEjD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAuC3B"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAS,MAAM,gBAAgB,CAAC;AAkBhD,qBAAa,qBAAsB,SAAQ,OAAO;IAChD,MAAM,CAAC,WAAW,SAAuD;IACzE,MAAM,CAAC,KAAK;;;MAAwE;IAEpF,MAAM,CAAC,IAAI;;;QAA4C;IAEjD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA0D3B"}
package/build/cli.js CHANGED
@@ -1,13 +1,24 @@
1
- import { ConfigProviderMemory, parseRgba } from '@basemaps/config';
1
+ // Configure the logging before importing everything
2
+ import { ConfigPrefix, ConfigProviderMemory, parseRgba } from '@basemaps/config';
3
+ import { TileSetLocal } from '@basemaps/lambda-tiler/build/cli/tile.set.local.js';
4
+ import { TileSets } from '@basemaps/lambda-tiler/build/tile.set.cache.js';
2
5
  import { Config, Env, LogConfig } from '@basemaps/shared';
3
6
  import { fsa } from '@linzjs/s3fs';
4
7
  import { Command, flags } from '@oclif/command';
5
- import { PrettyTransform } from 'pretty-json-log';
6
- import { ConfigPrefix } from '@basemaps/config';
8
+ import { basename, dirname } from 'path';
7
9
  import { BasemapsServer } from './server.js';
8
- if (process.stdout.isTTY)
9
- LogConfig.setOutputStream(PrettyTransform.stream());
10
10
  const logger = LogConfig.get();
11
+ const BaseProvider = {
12
+ id: 'pv_linz',
13
+ version: 1,
14
+ serviceIdentification: {},
15
+ serviceProvider: {
16
+ name: 'basemaps/server',
17
+ contact: {
18
+ address: {},
19
+ },
20
+ },
21
+ };
11
22
  export class BasemapsServerCommand extends Command {
12
23
  async run() {
13
24
  var _a;
@@ -20,8 +31,23 @@ export class BasemapsServerCommand extends Command {
20
31
  logger.info({ path: args.configPath }, 'Starting Server');
21
32
  const config = new ConfigProviderMemory();
22
33
  Config.setConfigProvider(config);
34
+ const tifSets = new Map();
23
35
  for await (const file of fsa.listDetails(args.configPath)) {
24
- if (!file.path.endsWith('.json'))
36
+ const lowerPath = file.path.toLowerCase();
37
+ if (lowerPath.endsWith('.tiff') || lowerPath.endsWith('.tif')) {
38
+ const tiffPath = dirname(file.path);
39
+ if (tifSets.has(tiffPath))
40
+ continue;
41
+ const tileSet = basename(tiffPath);
42
+ const tsl = new TileSetLocal(tileSet, tiffPath);
43
+ await tsl.load();
44
+ TileSets.add(tsl, new Date('3000-01-01').getTime());
45
+ const wmtsUrl = `${ServerUrl}/v1/tiles/${tileSet}/WMTSCapabilities.xml`;
46
+ logger.info({ tileSetId: tileSet, wmtsUrl }, 'TileSet:Loaded');
47
+ if (!config.objects.has('pv_linz'))
48
+ config.put(BaseProvider);
49
+ }
50
+ if (!lowerPath.endsWith('.json'))
25
51
  continue;
26
52
  logger.trace({ path: file.path, size: file.size }, 'Config:Load');
27
53
  const jsonData = await fsa.read(file.path).then((c) => JSON.parse(c.toString()));
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,cAAc,6CAAY,CAAC"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,cAAc,6CAAY,CAAC"}
package/build/server.js CHANGED
@@ -1,43 +1,39 @@
1
- import { HttpHeader, HttpHeaderRequestId, LambdaAlbRequest } from '@linzjs/lambda';
2
- import { handleRequest } from '@basemaps/lambda-tiler';
3
- import * as ulid from 'ulid';
1
+ import { handler } from '@basemaps/lambda-tiler';
2
+ import ulid from 'ulid';
4
3
  import express from 'express';
5
- import { LogConfig } from '@basemaps/shared';
4
+ import { lf } from '@linzjs/lambda';
6
5
  export const BasemapsServer = express();
6
+ function isAlbResult(r) {
7
+ if (typeof r !== 'object')
8
+ return false;
9
+ if (r == null)
10
+ return false;
11
+ return 'statusCode' in r;
12
+ }
13
+ const instanceId = ulid.ulid();
7
14
  BasemapsServer.get('/v1/*', async (req, res) => {
8
- const startTime = Date.now();
9
- const requestId = ulid.ulid();
10
- const logger = LogConfig.get().child({ id: requestId });
11
- const ctx = new LambdaAlbRequest({
12
- httpMethod: 'get',
15
+ const event = {
16
+ httpMethod: 'GET',
17
+ requestContext: { elb: { targetGroupArn: 'arn:fake' } },
13
18
  path: req.path,
19
+ headers: req.headers,
14
20
  queryStringParameters: req.query,
15
- }, {}, logger);
16
- if (ctx.header(HttpHeaderRequestId.RequestId) == null) {
17
- ctx.headers.set(HttpHeaderRequestId.RequestId, 'c' + requestId);
18
- }
19
- const ifNoneMatch = req.header(HttpHeader.IfNoneMatch);
20
- if (ifNoneMatch != null && !Array.isArray(ifNoneMatch)) {
21
- ctx.headers.set(HttpHeader.IfNoneMatch.toLowerCase(), ifNoneMatch);
22
- }
23
- try {
24
- const data = await handleRequest(ctx);
25
- res.status(data.status);
26
- if (data.headers) {
27
- for (const [header, value] of data.headers) {
28
- res.header(header, String(value));
29
- }
21
+ body: null,
22
+ isBase64Encoded: false,
23
+ };
24
+ if (req.query['api'] == null)
25
+ req.query['api'] = 'c' + instanceId;
26
+ handler(event, {}, (err, r) => {
27
+ var _a;
28
+ if (err || !isAlbResult(r)) {
29
+ lf.Logger.fatal({ err }, 'RequestFailed');
30
+ return res.end(err);
30
31
  }
31
- if (data.status < 299 && data.status > 199)
32
- res.end(data.body);
33
- else
34
- res.end();
35
- const duration = Date.now() - startTime;
36
- logger.info({ ...ctx.logContext, metrics: ctx.timer.metrics, status: data.status, duration }, 'Request:Done');
37
- }
38
- catch (e) {
39
- logger.fatal({ ...ctx.logContext, err: e }, 'Request:Failed');
40
- res.status(500);
32
+ res.status(r.statusCode);
33
+ for (const [key, value] of Object.entries((_a = r.headers) !== null && _a !== void 0 ? _a : {}))
34
+ res.header(key, String(value));
35
+ if (r.body)
36
+ res.send(Buffer.from(r.body, r.isBase64Encoded ? 'base64' : 'utf8'));
41
37
  res.end();
42
- }
38
+ });
43
39
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basemaps/server",
3
- "version": "6.10.0",
3
+ "version": "6.15.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/linz/basemaps.git",
@@ -34,8 +34,8 @@
34
34
  "dependencies": {
35
35
  "@basemaps/config": "^6.10.0",
36
36
  "@basemaps/geo": "^6.10.0",
37
- "@basemaps/lambda-tiler": "^6.10.0",
38
- "@basemaps/shared": "^6.10.0",
37
+ "@basemaps/lambda-tiler": "^6.15.0",
38
+ "@basemaps/shared": "^6.12.0",
39
39
  "@linzjs/lambda": "^2.0.0",
40
40
  "@oclif/command": "^1.8.0",
41
41
  "express": "^4.17.1",
@@ -44,5 +44,5 @@
44
44
  "devDependencies": {
45
45
  "@types/express": "^4.17.13"
46
46
  },
47
- "gitHead": "c88706ff58f4dfe83bf2b757d1483194accdb4c9"
47
+ "gitHead": "69cf1c417a9de62e7ac38b8a4d9309a1359260fa"
48
48
  }