From 4cdfc44da2d3216d476b465b34edd86a1c0a39b7 Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Wed, 16 Aug 2023 13:35:18 +0200 Subject: [PATCH] Config schema and clean-up, remove stacProxyUrl separated with ; in CLI, ... (#358) --- config.js | 3 +- config.schema.json | 279 ++++++++++++++++++++++++++++++++++++++++++++ docs/local_files.md | 2 +- docs/options.md | 6 +- src/store/index.js | 9 -- vue.config.js | 36 +++--- 6 files changed, 298 insertions(+), 37 deletions(-) create mode 100644 config.schema.json diff --git a/config.js b/config.js index 01110537a..d11922fd5 100644 --- a/config.js +++ b/config.js @@ -21,7 +21,6 @@ module.exports = { ], apiCatalogPriority: null, useTileLayerAsFallback: true, - tileSourceTemplate: null, displayGeoTiffByDefault: false, buildTileUrlTemplate: ({href, asset}) => "https://tiles.rdnt.io/tiles/{z}/{x}/{y}@2x?url=" + encodeURIComponent(asset.href.startsWith("/vsi") ? asset.href : href), stacProxyUrl: null, @@ -41,4 +40,4 @@ module.exports = { requestQueryParameters: {}, preprocessSTAC: null, authConfig: null -}; \ No newline at end of file +}; diff --git a/config.schema.json b/config.schema.json new file mode 100644 index 000000000..add6bfd47 --- /dev/null +++ b/config.schema.json @@ -0,0 +1,279 @@ +{ + "$comment": "Defines a JSON Schema for the config file. Note that JS functions are specified as type 'null' with format 'function'.", + "type": [ + "object" + ], + "properties": { + "catalogUrl": { + "type": [ + "string", + "null" + ], + "format": "uri" + }, + "catalogTitle": { + "type": [ + "string" + ] + }, + "allowExternalAccess": { + "type": [ + "boolean" + ] + }, + "allowedDomains": { + "type": [ + "array" + ], + "items": { + "type": [ + "string" + ] + } + }, + "detectLocaleFromBrowser": { + "type": [ + "boolean" + ] + }, + "storeLocale": { + "type": [ + "boolean" + ] + }, + "locale": { + "type": [ + "string" + ] + }, + "fallbackLocale": { + "type": [ + "string" + ] + }, + "supportedLocales": { + "type": [ + "array" + ], + "items": { + "type": [ + "string" + ] + } + }, + "apiCatalogPriority": { + "type": [ + "string", + "null" + ], + "enum": [ + "collections", + "childs", + null + ] + }, + "useTileLayerAsFallback": { + "type": [ + "boolean" + ] + }, + "displayGeoTiffByDefault": { + "type": [ + "boolean" + ] + }, + "buildTileUrlTemplate": { + "type": [ + "null" + ], + "format": "function", + "noCLI": true, + "noEnv": true + }, + "stacProxyUrl": { + "type": [ + "array", + "null" + ], + "prefixItems": [ + { + "type": [ + "string" + ], + "format": "uri-reference" + }, + { + "type": [ + "string" + ], + "format": "uri" + } + ], + "items": false + }, + "pathPrefix": { + "type": [ + "string" + ], + "buildOnly": true + }, + "historyMode": { + "type": [ + "string" + ], + "enum": [ + "history", + "hash" + ], + "buildOnly": true + }, + "cardViewMode": { + "type": [ + "string" + ], + "enum": [ + "list", + "cards" + ] + }, + "cardViewSort": { + "type": [ + "string", + "null" + ], + "enum": [ + "asc", + "desc", + null + ] + }, + "showThumbnailsAsAssets": { + "type": [ + "boolean" + ] + }, + "stacLint": { + "type": [ + "boolean" + ] + }, + "geoTiffResolution": { + "type": [ + "integer" + ], + "minimum": 1 + }, + "redirectLegacyUrls": { + "type": [ + "boolean" + ] + }, + "itemsPerPage": { + "type": [ + "integer" + ], + "minimum": 1 + }, + "defaultThumbnailSize": { + "type": [ + "array", + "null" + ], + "minItems": 2, + "maxItems": 2, + "items": { + "type": [ + "number" + ] + } + }, + "maxPreviewsOnMap": { + "type": [ + "integer" + ], + "minimum": 1 + }, + "crossOriginMedia": { + "type": [ + "string", + "null" + ], + "enum": [ + "anonymous", + "use-credentials", + "", + null + ] + }, + "requestHeaders": { + "type": [ + "object" + ], + "noCLI": true, + "noEnv": false + }, + "requestQueryParameters": { + "type": [ + "object" + ], + "noCLI": true, + "noEnv": true + }, + "preprocessSTAC": { + "type": [ + "null" + ], + "format": "function", + "noCLI": true, + "noEnv": true + }, + "authConfig": { + "type": [ + "object" + ], + "properties": { + "type": { + "type": [ + "null", + "string" + ], + "enum": [ + "query", + "header" + ] + }, + "key": { + "type": [ + "string" + ] + }, + "formatter": { + "oneOf": [ + { + "type": [ + "null" + ], + "format": "function" + }, + { + "type": [ + "string" + ], + "enum": [ + "Bearer" + ] + } + ] + }, + "description": { + "type": [ + "string", + "null" + ] + } + }, + "noCLI": true, + "noEnv": true + } + } +} diff --git a/docs/local_files.md b/docs/local_files.md index 0aff746da..75ca3011c 100644 --- a/docs/local_files.md +++ b/docs/local_files.md @@ -14,7 +14,7 @@ npx http-server -p 8000 --cors You can then use the CLI option `--catalogUrl="http://localhost:8000/catalog.json"` when starting STAC Browser. -If your catalog uses absolute file locations, you can use the [`stacProxyUrl`](options.md#stacproxyurl) option to convert local file locations to local web browser URLs. For instance, if you are serving a catalog on the local file system at `/home/user/catalog.json`, but want to serve the data out from a server located at `http://localhost:8000/`, you can use `--stacProxyUrl="/home/user;http://localhost:8000"`. +If your catalog uses absolute file locations, you can use the [`stacProxyUrl`](options.md#stacproxyurl) option to convert local file locations to local web browser URLs. For instance, if you are serving a catalog on the local file system at `/home/user/catalog.json`, but want to serve the data out from a server located at `http://localhost:8000/`, you can use `--stacProxyUrl=/home/user http://localhost:8000`. ## Using STAC Browser somewhere else diff --git a/docs/options.md b/docs/options.md index 12a56b79c..5661e06f6 100644 --- a/docs/options.md +++ b/docs/options.md @@ -121,7 +121,7 @@ Enables or disables a feature that validates the STAC catalog when opening the " Validation uses the external service [staclint.com](https://staclint.com). Validation is automatically disabled in the following cases: -- the host of a catalog is `localhost`, `127.0.0.1` and `::1` +- the host of a catalog is `localhost`, `127.0.0.1` or `::1` - [private query parameters](../README.md#private-query-parameters) have been set - `stacProxyUrl` is set @@ -156,7 +156,7 @@ For instance, if you are serving a catalog on the local file system at `/home/us the data out from a server located at `http://localhost:8888/`, you can use: ```bash -npm start -- --open --stacProxyUrl="/home/user;http://localhost:8888" +npm start -- --open --stacProxyUrl=/home/user http://localhost:8888 ``` Notice the format of the value: @@ -332,4 +332,4 @@ preprocessSTAC: (stac, state) => { } return stac; } -``` \ No newline at end of file +``` diff --git a/src/store/index.js b/src/store/index.js index a1bf2f27e..e0c8c7f1f 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -384,15 +384,6 @@ function getStore(config, router) { state.catalogUrl = value; } break; - case 'stacProxyUrl': - // Proxy URLs coming from CLI have the form https://thingtoproxy.com;http://proxy:111 - if (typeof value === 'string' && value.includes(';')) { - state[key] = value.split(';'); - } - else { - state[key] = value; - } - break; case 'crossOriginMedia': state.crossOriginMedia = ['anonymous', 'use-credentials'].includes(value) ? value : null; break; diff --git a/vue.config.js b/vue.config.js index dca05bd6a..064f13c3b 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,38 +1,30 @@ const yargs = require('yargs/yargs'); const { hideBin } = require('yargs/helpers'); +const path = require('path'); +const NodePolyfillPlugin = require('node-polyfill-webpack-plugin'); + +const { properties } = require('./config.schema.json'); +const pkgFile = require('./package.json'); + +const optionsForType = (type) => Object.entries(properties) + .filter(([_, schema]) => Array.isArray(schema.type) && schema.type.includes(type)) + .map(([key]) => key); const argv = yargs(hideBin(process.argv)) .parserConfiguration({'camel-case-expansion': false}) .env('SB') - .boolean([ - 'allowExternalAccess', - 'displayGeoTiffByDefault', - 'redirectLegacyUrls', - 'showThumbnailsAsAssets', - 'stacLint', - 'useTileLayerAsFallback', - 'noSourceMaps' - ]) - .number([ - 'itemsPerPage', - 'maxPreviewsOnMap' - ]) - .array([ - 'supportedLocales' - ]) + .boolean(optionsForType("boolean")) + .number(optionsForType("number").concat(optionsForType("integer"))) + .array(optionsForType("array")) .argv; // Clean-up arguments delete argv._; delete argv.$0; -const pkgFile = require('./package.json'); - -const path = require('path'); const configFile = path.resolve(argv.CONFIG ? argv.CONFIG : './config.js'); const configFromFile = require(configFile); const mergedConfig = Object.assign(configFromFile, argv); -const NodePolyfillPlugin = require('node-polyfill-webpack-plugin'); -const config = { +const vueConfig = { lintOnSave: process.env.NODE_ENV !== 'production', productionSourceMap: !mergedConfig.noSourceMaps, publicPath: mergedConfig.pathPrefix, @@ -69,4 +61,4 @@ const config = { } }; -module.exports = config; \ No newline at end of file +module.exports = vueConfig;