tileserver-gl-light 4.1.2 → 4.2.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/.eslintrc.cjs ADDED
@@ -0,0 +1,32 @@
1
+ module.exports = {
2
+ root: true,
3
+ env: {
4
+ browser: true,
5
+ node: true,
6
+ es6: true,
7
+ },
8
+ parserOptions: {
9
+ parser: '@typescript-eslint/parser',
10
+ ecmaVersion: 2020,
11
+ sourceType: 'module',
12
+ lib: ['es2020'],
13
+ ecmaFeatures: {
14
+ jsx: true,
15
+ tsx: true,
16
+ },
17
+ },
18
+ plugins: ['prettier', 'jsdoc', 'security'],
19
+ extends: [
20
+ 'prettier',
21
+ 'plugin:@typescript-eslint/recommended',
22
+ 'plugin:@typescript-eslint/eslint-recommended',
23
+ 'plugin:prettier/recommended',
24
+ 'plugin:jsdoc/recommended',
25
+ 'plugin:security/recommended',
26
+ ],
27
+ // add your custom rules here
28
+ rules: {
29
+ 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
30
+ 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
31
+ },
32
+ };
package/.gitattributes ADDED
@@ -0,0 +1,11 @@
1
+ ###############################################################################
2
+ # Set default behavior to automatically normalize line endings.
3
+ ###############################################################################
4
+ * text=auto
5
+
6
+ ###############################################################################
7
+ # behavior for Unix scripts
8
+ #
9
+ # Unix scripts are treated as binary by default.
10
+ ###############################################################################
11
+ *.sh eol=lf
@@ -0,0 +1,21 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ NAME=$(git config user.name)
5
+ EMAIL=$(git config user.email)
6
+
7
+ if [ -z "$NAME" ]; then
8
+ echo "empty git config user.name"
9
+ exit 1
10
+ fi
11
+
12
+ if [ -z "$EMAIL" ]; then
13
+ echo "empty git config user.email"
14
+ exit 1
15
+ fi
16
+
17
+ git interpret-trailers --if-exists doNothing --trailer \
18
+ "Signed-off-by: $NAME <$EMAIL>" \
19
+ --in-place "$1"
20
+
21
+ npm exec --no -- commitlint --edit $1
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm exec --no -- lint-staged --no-stash
package/Dockerfile CHANGED
@@ -20,7 +20,9 @@ RUN set -ex; \
20
20
  apt-get clean; \
21
21
  rm -rf /var/lib/apt/lists/*;
22
22
 
23
- EXPOSE 80
23
+ EXPOSE 8080
24
+
25
+ RUN mkdir -p /data && chown node:node /data
24
26
  VOLUME /data
25
27
  WORKDIR /data
26
28
  ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"]
@@ -30,3 +32,4 @@ COPY / /usr/src/app
30
32
  RUN cd /usr/src/app && npm install --omit=dev
31
33
  RUN ["chmod", "+x", "/usr/src/app/docker-entrypoint.sh"]
32
34
  USER node:node
35
+ HEALTHCHECK CMD node /usr/src/app/src/healthcheck.js
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: ['@commitlint/config-conventional'],
3
+ };
@@ -20,7 +20,7 @@ trap refresh HUP
20
20
 
21
21
  if ! which -- "${1}"; then
22
22
  # first arg is not an executable
23
- node /usr/src/app/ -p 80 "$@" &
23
+ node /usr/src/app/ "$@" &
24
24
  # Wait exits immediately on signals which have traps set. Store return value and wait
25
25
  # again for all jobs to actually complete before continuing.
26
26
  wait $! || RETVAL=$?
@@ -7,7 +7,7 @@ Docker
7
7
 
8
8
  When running docker image, no special installation is needed -- the docker will automatically download the image if not present.
9
9
 
10
- Just run ``docker run --rm -it -v $(pwd):/data -p 8080:80 maptiler/tileserver-gl``.
10
+ Just run ``docker run --rm -it -v $(pwd):/data -p 8080:8080 maptiler/tileserver-gl``.
11
11
 
12
12
  Additional options (see :doc:`/usage`) can be passed to the TileServer GL by appending them to the end of this command. You can, for example, do the following:
13
13
 
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ '*.{js,ts}': 'npm run lint:js',
3
+ '*.{yml}': 'npm run lint:yml',
4
+ };
package/package.json CHANGED
@@ -1,21 +1,20 @@
1
1
  {
2
2
  "name": "tileserver-gl-light",
3
- "version": "4.1.2",
3
+ "version": "4.2.0",
4
4
  "description": "Map tile server for JSON GL styles - serving vector tiles",
5
5
  "main": "src/main.js",
6
6
  "bin": "src/main.js",
7
7
  "type": "module",
8
- "repository": {
9
- "type": "git",
10
- "url": "git+https://github.com/maptiler/tileserver-gl.git"
11
- },
12
- "license": "BSD-2-Clause",
13
- "engines": {
14
- "node": ">= 14.15.0"
15
- },
16
8
  "scripts": {
17
9
  "test": "mocha test/**.js --timeout 10000",
18
- "docker": "docker build -f Dockerfile . && docker run --rm -i -p 8080:80 $(docker build -q .)"
10
+ "lint:yml": "yamllint --schema=CORE_SCHEMA *.{yml,yaml}",
11
+ "lint:js": "npm run lint:eslint && npm run lint:prettier",
12
+ "lint:js:fix": "npm run lint:eslint:fix && npm run lint:prettier:fix",
13
+ "lint:eslint": "eslint \"{,!(node_modules|dist|static|public)/**/}*.{js,ts,cjs,mjs}\" --ignore-path .gitignore",
14
+ "lint:eslint:fix": "eslint --fix \"{,!(node_modules|dist|static|public)/**/}*.{js,ts,cjs,mjs}\" --ignore-path .gitignore",
15
+ "lint:prettier": "prettier --check \"{,!(node_modules|dist|static|public)/**/}*.{js,ts,cjs,mjs,json}\" --ignore-path .gitignore",
16
+ "lint:prettier:fix": "prettier --write \"{,!(node_modules|dist|static|public)/**/}*.{js,ts,cjs,mjs,json}\" --ignore-path .gitignore",
17
+ "docker": "docker build -f Dockerfile . && docker run --rm -i -p 8080:8080 $(docker build -q .)"
19
18
  },
20
19
  "dependencies": {
21
20
  "@mapbox/glyph-pbf-composite": "0.0.3",
@@ -38,5 +37,23 @@
38
37
  "request": "2.88.2",
39
38
  "tileserver-gl-styles": "2.0.0",
40
39
  "sanitize-filename": "1.6.3"
41
- }
40
+ },
41
+ "keywords": [
42
+ "maptiler",
43
+ "tileserver-gl",
44
+ "maplibre-gl",
45
+ "tileserver"
46
+ ],
47
+ "license": "BSD-2-Clause",
48
+ "engines": {
49
+ "node": ">= 14.15.0"
50
+ },
51
+ "repository": {
52
+ "url": "git+https://github.com/maptiler/tileserver-gl.git",
53
+ "type": "git"
54
+ },
55
+ "bugs": {
56
+ "url": "https://github.com/maptiler/tileserver-gl/issues"
57
+ },
58
+ "homepage": "https://github.com/maptiler/tileserver-gl#readme"
42
59
  }
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ $schema: 'http://json.schemastore.org/prettierrc',
3
+ semi: true,
4
+ arrowParens: 'always',
5
+ singleQuote: true,
6
+ trailingComma: 'all',
7
+ bracketSpacing: true,
8
+ htmlWhitespaceSensitivity: 'css',
9
+ insertPragma: false,
10
+ tabWidth: 2,
11
+ useTabs: false,
12
+ endOfLine: 'lf',
13
+ };
package/publish.js CHANGED
@@ -12,25 +12,33 @@
12
12
 
13
13
  // SYNC THE `light` FOLDER
14
14
 
15
- import child_process from 'child_process'
16
- child_process.execSync('rsync -av --exclude="light" --exclude=".git" --exclude="node_modules" --delete . light', {
17
- stdio: 'inherit'
18
- });
15
+ import child_process from 'child_process';
16
+ child_process.execSync(
17
+ 'rsync -av --exclude="light" --exclude=".git" --exclude="node_modules" --delete . light',
18
+ {
19
+ stdio: 'inherit',
20
+ },
21
+ );
19
22
 
20
23
  // PATCH `package.json`
21
24
  import fs from 'fs';
22
25
  import path from 'path';
23
- import {fileURLToPath} from 'url';
26
+ import { fileURLToPath } from 'url';
24
27
  const __filename = fileURLToPath(import.meta.url);
25
28
  const __dirname = path.dirname(__filename);
26
- const packageJson = JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf8'))
29
+ const packageJson = JSON.parse(
30
+ fs.readFileSync(__dirname + '/package.json', 'utf8'),
31
+ );
27
32
 
28
33
  packageJson.name += '-light';
29
- packageJson.description = 'Map tile server for JSON GL styles - serving vector tiles';
34
+ packageJson.description =
35
+ 'Map tile server for JSON GL styles - serving vector tiles';
30
36
  delete packageJson.dependencies['canvas'];
31
37
  delete packageJson.dependencies['@maplibre/maplibre-gl-native'];
32
38
  delete packageJson.dependencies['sharp'];
33
39
 
40
+ delete packageJson.scripts['prepare'];
41
+
34
42
  delete packageJson.optionalDependencies;
35
43
  delete packageJson.devDependencies;
36
44
 
@@ -51,10 +59,10 @@ if (process.argv.length > 2 && process.argv[2] == '--no-publish') {
51
59
 
52
60
  // tileserver-gl
53
61
  child_process.execSync('npm publish . --access public', {
54
- stdio: 'inherit'
62
+ stdio: 'inherit',
55
63
  });
56
64
 
57
65
  // tileserver-gl-light
58
66
  child_process.execSync('npm publish ./light --access public', {
59
- stdio: 'inherit'
67
+ stdio: 'inherit',
60
68
  });
package/run.sh CHANGED
@@ -29,7 +29,7 @@ export DISPLAY=:${displayNumber}.${screenNumber}
29
29
 
30
30
  echo
31
31
  cd /data
32
- node /usr/src/app/ -p 80 "$@" &
32
+ node /usr/src/app/ "$@" &
33
33
  child=$!
34
34
  wait "$child"
35
35
 
@@ -0,0 +1,18 @@
1
+ import * as http from 'http';
2
+ var options = {
3
+ timeout: 2000,
4
+ };
5
+ var url = 'http://localhost:8080/health';
6
+ var request = http.request(url, options, (res) => {
7
+ console.log(`STATUS: ${res.statusCode}`);
8
+ if (res.statusCode == 200) {
9
+ process.exit(0);
10
+ } else {
11
+ process.exit(1);
12
+ }
13
+ });
14
+ request.on('error', function (err) {
15
+ console.log('ERROR');
16
+ process.exit(1);
17
+ });
18
+ request.end();
package/src/main.js CHANGED
@@ -4,73 +4,52 @@
4
4
 
5
5
  import fs from 'node:fs';
6
6
  import path from 'path';
7
- import {fileURLToPath} from 'url';
7
+ import { fileURLToPath } from 'url';
8
8
  import request from 'request';
9
- import {server} from './server.js';
9
+ import { server } from './server.js';
10
10
 
11
11
  import MBTiles from '@mapbox/mbtiles';
12
12
 
13
13
  const __filename = fileURLToPath(import.meta.url);
14
14
  const __dirname = path.dirname(__filename);
15
- const packageJson = JSON.parse(fs.readFileSync(__dirname + '/../package.json', 'utf8'));
15
+ const packageJson = JSON.parse(
16
+ fs.readFileSync(__dirname + '/../package.json', 'utf8'),
17
+ );
16
18
 
17
19
  const args = process.argv;
18
20
  if (args.length >= 3 && args[2][0] !== '-') {
19
21
  args.splice(2, 0, '--mbtiles');
20
22
  }
21
23
 
22
- import {program} from 'commander';
24
+ import { program } from 'commander';
23
25
  program
24
26
  .description('tileserver-gl startup options')
25
27
  .usage('tileserver-gl [mbtiles] [options]')
26
28
  .option(
27
29
  '--mbtiles <file>',
28
30
  'MBTiles file (uses demo configuration);\n' +
29
- '\t ignored if the configuration file is also specified'
31
+ '\t ignored if the configuration file is also specified',
30
32
  )
31
33
  .option(
32
34
  '-c, --config <file>',
33
35
  'Configuration file [config.json]',
34
- 'config.json'
35
- )
36
- .option(
37
- '-b, --bind <address>',
38
- 'Bind address'
39
- )
40
- .option(
41
- '-p, --port <port>',
42
- 'Port [8080]',
43
- 8080,
44
- parseInt
45
- )
46
- .option(
47
- '-C|--no-cors',
48
- 'Disable Cross-origin resource sharing headers'
36
+ 'config.json',
49
37
  )
38
+ .option('-b, --bind <address>', 'Bind address')
39
+ .option('-p, --port <port>', 'Port [8080]', 8080, parseInt)
40
+ .option('-C|--no-cors', 'Disable Cross-origin resource sharing headers')
50
41
  .option(
51
42
  '-u|--public_url <url>',
52
- 'Enable exposing the server on subpaths, not necessarily the root of the domain'
53
- )
54
- .option(
55
- '-V, --verbose',
56
- 'More verbose output'
57
- )
58
- .option(
59
- '-s, --silent',
60
- 'Less verbose output'
61
- )
62
- .option(
63
- '-l|--log_file <file>',
64
- 'output log file (defaults to standard out)'
43
+ 'Enable exposing the server on subpaths, not necessarily the root of the domain',
65
44
  )
45
+ .option('-V, --verbose', 'More verbose output')
46
+ .option('-s, --silent', 'Less verbose output')
47
+ .option('-l|--log_file <file>', 'output log file (defaults to standard out)')
66
48
  .option(
67
49
  '-f|--log_format <format>',
68
- 'define the log format: https://github.com/expressjs/morgan#morganformat-options'
69
- )
70
- .version(
71
- packageJson.version,
72
- '-v, --version'
50
+ 'define the log format: https://github.com/expressjs/morgan#morganformat-options',
73
51
  )
52
+ .version(packageJson.version, '-v, --version');
74
53
  program.parse(process.argv);
75
54
  const opts = program.opts();
76
55
 
@@ -91,14 +70,16 @@ const startServer = (configPath, config) => {
91
70
  silent: opts.silent,
92
71
  logFile: opts.log_file,
93
72
  logFormat: opts.log_format,
94
- publicUrl: publicUrl
73
+ publicUrl: publicUrl,
95
74
  });
96
75
  };
97
76
 
98
77
  const startWithMBTiles = (mbtilesFile) => {
99
78
  console.log(`[INFO] Automatically creating config file for ${mbtilesFile}`);
100
79
  console.log(`[INFO] Only a basic preview style will be used.`);
101
- console.log(`[INFO] See documentation to learn how to create config.json file.`);
80
+ console.log(
81
+ `[INFO] See documentation to learn how to create config.json file.`,
82
+ );
102
83
 
103
84
  mbtilesFile = path.resolve(process.cwd(), mbtilesFile);
104
85
 
@@ -110,60 +91,70 @@ const startWithMBTiles = (mbtilesFile) => {
110
91
  const instance = new MBTiles(mbtilesFile + '?mode=ro', (err) => {
111
92
  if (err) {
112
93
  console.log('ERROR: Unable to open MBTiles.');
113
- console.log(` Make sure ${path.basename(mbtilesFile)} is valid MBTiles.`);
94
+ console.log(`Make sure ${path.basename(mbtilesFile)} is valid MBTiles.`);
114
95
  process.exit(1);
115
96
  }
116
97
 
117
98
  instance.getInfo((err, info) => {
118
99
  if (err || !info) {
119
100
  console.log('ERROR: Metadata missing in the MBTiles.');
120
- console.log(` Make sure ${path.basename(mbtilesFile)} is valid MBTiles.`);
101
+ console.log(
102
+ `Make sure ${path.basename(mbtilesFile)} is valid MBTiles.`,
103
+ );
121
104
  process.exit(1);
122
105
  }
123
106
  const bounds = info.bounds;
124
107
 
125
- const styleDir = path.resolve(__dirname, '../node_modules/tileserver-gl-styles/');
108
+ const styleDir = path.resolve(
109
+ __dirname,
110
+ '../node_modules/tileserver-gl-styles/',
111
+ );
126
112
 
127
113
  const config = {
128
- 'options': {
129
- 'paths': {
130
- 'root': styleDir,
131
- 'fonts': 'fonts',
132
- 'styles': 'styles',
133
- 'mbtiles': path.dirname(mbtilesFile)
134
- }
114
+ options: {
115
+ paths: {
116
+ root: styleDir,
117
+ fonts: 'fonts',
118
+ styles: 'styles',
119
+ mbtiles: path.dirname(mbtilesFile),
120
+ },
135
121
  },
136
- 'styles': {},
137
- 'data': {}
122
+ styles: {},
123
+ data: {},
138
124
  };
139
125
 
140
- if (info.format === 'pbf' &&
141
- info.name.toLowerCase().indexOf('openmaptiles') > -1) {
126
+ if (
127
+ info.format === 'pbf' &&
128
+ info.name.toLowerCase().indexOf('openmaptiles') > -1
129
+ ) {
142
130
  config['data'][`v3`] = {
143
- 'mbtiles': path.basename(mbtilesFile)
131
+ mbtiles: path.basename(mbtilesFile),
144
132
  };
145
133
 
146
-
147
134
  const styles = fs.readdirSync(path.resolve(styleDir, 'styles'));
148
135
  for (const styleName of styles) {
149
136
  const styleFileRel = styleName + '/style.json';
150
137
  const styleFile = path.resolve(styleDir, 'styles', styleFileRel);
151
138
  if (fs.existsSync(styleFile)) {
152
139
  config['styles'][styleName] = {
153
- 'style': styleFileRel,
154
- 'tilejson': {
155
- 'bounds': bounds
156
- }
140
+ style: styleFileRel,
141
+ tilejson: {
142
+ bounds: bounds,
143
+ },
157
144
  };
158
145
  }
159
146
  }
160
147
  } else {
161
- console.log(`WARN: MBTiles not in "openmaptiles" format. Serving raw data only...`);
162
- config['data'][(info.id || 'mbtiles')
148
+ console.log(
149
+ `WARN: MBTiles not in "openmaptiles" format. Serving raw data only...`,
150
+ );
151
+ config['data'][
152
+ (info.id || 'mbtiles')
163
153
  .replace(/\//g, '_')
164
154
  .replace(/:/g, '_')
165
- .replace(/\?/g, '_')] = {
166
- 'mbtiles': path.basename(mbtilesFile)
155
+ .replace(/\?/g, '_')
156
+ ] = {
157
+ mbtiles: path.basename(mbtilesFile),
167
158
  };
168
159
  }
169
160
 
@@ -197,7 +188,8 @@ fs.stat(path.resolve(opts.config), (err, stats) => {
197
188
  console.log(`No MBTiles specified, using ${mbtiles}`);
198
189
  return startWithMBTiles(mbtiles);
199
190
  } else {
200
- const url = 'https://github.com/maptiler/tileserver-gl/releases/download/v1.3.0/zurich_switzerland.mbtiles';
191
+ const url =
192
+ 'https://github.com/maptiler/tileserver-gl/releases/download/v1.3.0/zurich_switzerland.mbtiles';
201
193
  const filename = 'zurich_switzerland.mbtiles';
202
194
  const stream = fs.createWriteStream(filename);
203
195
  console.log(`No MBTiles found`);