From aa4b82a69f06e2b40a3aed5e58d598035751cd68 Mon Sep 17 00:00:00 2001 From: Candid Dauth Date: Sat, 17 Feb 2024 04:57:21 +0100 Subject: [PATCH] Allow specifying a custom app name, calculate base URL for opensearch.xml --- config.env.example | 9 +++++++ docs/src/developers/server/config.md | 7 ++++- docs/src/developers/server/docker.md | 4 ++- frontend/build.d.ts | 4 ++- frontend/build.js | 4 ++- .../facil-map-context-provider.vue | 10 ++++--- .../facil-map-context.ts | 1 + frontend/src/lib/components/facil-map.vue | 2 ++ .../components/leaflet-map/leaflet-map.vue | 2 +- frontend/src/lib/components/share-dialog.vue | 4 +-- .../toolbox/toolbox-help-dropdown.vue | 5 +++- frontend/{public/static => src}/manifest.json | 8 +++--- frontend/src/map/map.ejs | 10 +++---- frontend/src/map/map.ts | 3 ++- .../opensearch.xml => src/opensearch.xml.ejs} | 6 ++--- frontend/src/table/table.ejs | 4 +-- server/src/config.ts | 11 ++++++++ server/src/frontend.ts | 27 ++++++++++++++++--- server/src/utils/streams.ts | 2 +- server/src/webserver.ts | 21 ++++++++++++++- utils/src/types.ts | 1 + 21 files changed, 114 insertions(+), 31 deletions(-) rename frontend/{public/static => src}/manifest.json (59%) rename frontend/{public/static/opensearch.xml => src/opensearch.xml.ejs} (77%) diff --git a/config.env.example b/config.env.example index 89a0fb88..b377189a 100644 --- a/config.env.example +++ b/config.env.example @@ -1,6 +1,15 @@ # HTTP requests made by the backend will send this User-Agent header. Please adapt to your URL and e-mail address. #USER_AGENT=FacilMap (https://facilmap.org/, cdauth@cdauth.eu) +# Whether to trust the X-Forwarded-* headers. Can be "true" or a comma-separated list of IP subnets. +# See https://expressjs.com/en/guide/behind-proxies.html for details. +#TRUST_PROXY=true +# Alternatively, manually set the base URL where FacilMap will be publicly reachable. +#BASE_URL=https://facilmap.org/ + +# The name of the app that should be displayed throughout the UI. +#APP_NAME=FacilMap + # On which IP the HTTP server will listen. Leave empty to listen to all IPs. #HOST= # On which port the HTTP server will listen. diff --git a/docs/src/developers/server/config.md b/docs/src/developers/server/config.md index 08f66c32..e51a635e 100644 --- a/docs/src/developers/server/config.md +++ b/docs/src/developers/server/config.md @@ -5,6 +5,9 @@ The config of the FacilMap server can be set either by using environment variabl | Variable | Required | Default | Meaning | |-----------------------|----------|-------------|----------------------------------------------------------------------------------------------------------------------------------| | `USER_AGENT` | * | | Will be used for all HTTP requests (search, routing, GPX/KML/OSM/GeoJSON files). You better provide your e-mail address in here. | +| `APP_NAME` | | | If specified, will replace “FacilMap” as the name of the app throughout the UI. | +| `TRUST_PROXY` | | | Whether to trust the X-Forwarded-* headers. Can be `true` or a comma-separated list of IP subnets (see the [express documentation](https://expressjs.com/en/guide/behind-proxies.html)). Currently only used to calculate the base URL for the `opensearch.xml` file. | +| `BASE_URL` | | | If `TRUST_PROXY` does not work for your particular setup, you can manually specify the base URL where FacilMap can be publicly reached here. | | `HOST` | | | The ip address to listen on (leave empty to listen on all addresses) | | `PORT` | | `8080` | The port to listen on. | | `DB_TYPE` | | `mysql` | The type of database. Either `mysql`, `postgres`, `mariadb`, `sqlite`, or `mssql`. | @@ -18,8 +21,10 @@ The config of the FacilMap server can be set either by using environment variabl | `MAPZEN_TOKEN` | | | [Mapzen API key](https://mapzen.com/developers/sign_up). | | `MAXMIND_USER_ID` | | | [MaxMind user ID](https://www.maxmind.com/en/geolite2/signup). | | `MAXMIND_LICENSE_KEY` | | | MaxMind license key. | +| `LIMA_LABS_TOKEN` | | | [Lima Labs](https://maps.lima-labs.com/) API key FacilMap makes use of several third-party services that require you to register (for free) and generate an API key: * Mapbox and OpenRouteService are used for calculating routes. Mapbox is used for basic routes, OpenRouteService is used when custom route mode settings are made. If these API keys are not defined, calculating routes will fail. * Maxmind provides a free database that maps IP addresses to approximate locations. FacilMap downloads this database to decide the initial map view for users (IP addresses are looked up in FacilMap’s copy of the database, on IP addresses are sent to Maxmind). This API key is optional, if it is not set, the default view will be the whole world. -* Mapzen is used to look up the elevation info for search results. The API key is optional, if it is not set, no elevation info will be available for search results. \ No newline at end of file +* Mapzen is used to look up the elevation info for search results. The API key is optional, if it is not set, no elevation info will be available for search results. +* Lima Labs is used for nicer and higher resolution map tiles than Mapnik. The API key is optional, if it is not set, Mapnik will be the default map style instead. \ No newline at end of file diff --git a/docs/src/developers/server/docker.md b/docs/src/developers/server/docker.md index 6c047c5f..0ef3070b 100644 --- a/docs/src/developers/server/docker.md +++ b/docs/src/developers/server/docker.md @@ -23,6 +23,7 @@ services: - db environment: USER_AGENT: My FacilMap (https://facilmap.example.org/, facilmap@example.org) + TRUST_PROXY: "true" DB_TYPE: mysql DB_HOST: db DB_NAME: facilmap @@ -59,6 +60,7 @@ services: - db environment: USER_AGENT: My FacilMap (https://facilmap.example.org/, facilmap@example.org) + TRUST_PROXY: "true" DB_TYPE: postgres DB_HOST: db DB_NAME: facilmap @@ -88,5 +90,5 @@ To manually create the necessary docker containers, use these commands: ```bash docker create --name=facilmap_db -e MYSQL_DATABASE=facilmap -e MYSQL_USER=facilmap -e MYSQL_PASSWORD=password -e MYSQL_RANDOM_ROOT_PASSWORD=true --restart=unless-stopped mariadb --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci -docker create --link=facilmap_db -p 8080 --name=facilmap -e "USER_AGENT=My FacilMap (https://facilmap.example.org/, facilmap@example.org)" -e DB_TYPE=mysql -e DB_HOST=facilmap_db -e DB_NAME=facilmap -e DB_USER=facilmap -e DB_PASSWORD=facilmap -e ORS_TOKEN= -e MAPBOX_TOKEN= -e MAPZEN_TOKEN= -e MAXMIND_USER_ID= -e MAXMIND_LICENSE_KEY= -e LIMA_LABS_TOKEN= --restart=unless-stopped facilmap/facilmap +docker create --link=facilmap_db -p 8080 --name=facilmap -e "USER_AGENT=My FacilMap (https://facilmap.example.org/, facilmap@example.org)" -e TRUST_PROXY=true -e DB_TYPE=mysql -e DB_HOST=facilmap_db -e DB_NAME=facilmap -e DB_USER=facilmap -e DB_PASSWORD=facilmap -e ORS_TOKEN= -e MAPBOX_TOKEN= -e MAPZEN_TOKEN= -e MAXMIND_USER_ID= -e MAXMIND_LICENSE_KEY= -e LIMA_LABS_TOKEN= --restart=unless-stopped facilmap/facilmap ``` \ No newline at end of file diff --git a/frontend/build.d.ts b/frontend/build.d.ts index b9fe8bcf..d7b4bf38 100644 --- a/frontend/build.d.ts +++ b/frontend/build.d.ts @@ -8,7 +8,9 @@ export const paths: { mapEjs: string; tableEntry: string; tableEjs: string; - manifest: string; + viteManifest: string; + pwaManifest: string; + opensearchXmlEjs: string; }; export function serve(inlineConfig?: InlineConfig): Promise; diff --git a/frontend/build.js b/frontend/build.js index ddbf3623..0cbcf561 100644 --- a/frontend/build.js +++ b/frontend/build.js @@ -13,7 +13,9 @@ export const paths = { mapEjs: `${root}/src/map/map.ejs`, tableEntry: "src/table/table.ts", tableEjs: `${root}/src/table/table.ejs`, - manifest: `${dist}/.vite/manifest.json`, + viteManifest: `${dist}/.vite/manifest.json`, + pwaManifest: `${root}/src/manifest.json`, + opensearchXmlEjs: `${root}/src/opensearch.xml.ejs`, }; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types diff --git a/frontend/src/lib/components/facil-map-context-provider/facil-map-context-provider.vue b/frontend/src/lib/components/facil-map-context-provider/facil-map-context-provider.vue index c4eb135c..3ddae2e2 100644 --- a/frontend/src/lib/components/facil-map-context-provider/facil-map-context-provider.vue +++ b/frontend/src/lib/components/facil-map-context-provider/facil-map-context-provider.vue @@ -36,10 +36,13 @@ @@ -185,7 +185,7 @@ -

Add this HTML code to a web page to embed FacilMap. Learn more

+

Add this HTML code to a web page to embed {{context.appName}}. Learn more

\ No newline at end of file diff --git a/frontend/src/lib/components/toolbox/toolbox-help-dropdown.vue b/frontend/src/lib/components/toolbox/toolbox-help-dropdown.vue index 1cd7f84f..8c20c64e 100644 --- a/frontend/src/lib/components/toolbox/toolbox-help-dropdown.vue +++ b/frontend/src/lib/components/toolbox/toolbox-help-dropdown.vue @@ -2,6 +2,9 @@ import AboutDialog from "../about-dialog.vue"; import { ref } from "vue"; import DropdownMenu from "../ui/dropdown-menu.vue"; + import { injectContextRequired } from "../facil-map-context-provider/facil-map-context-provider.vue"; + + const context = injectContextRequired(); const emit = defineEmits<{ "hide-sidebar": []; @@ -63,7 +66,7 @@ @click="dialog = 'about'; emit('hide-sidebar')" href="javascript:" draggable="false" - >About FacilMap + >About {{context.appName}} diff --git a/frontend/public/static/manifest.json b/frontend/src/manifest.json similarity index 59% rename from frontend/public/static/manifest.json rename to frontend/src/manifest.json index fe78bc64..1654cd39 100644 --- a/frontend/public/static/manifest.json +++ b/frontend/src/manifest.json @@ -1,13 +1,13 @@ { - "name": "FacilMap", - "short_name": "FacilMap", + "name": "%APP_NAME%", + "short_name": "%APP_NAME%", "icons": [{ - "src": "./app-512.png", + "src": "./static/app-512.png", "sizes": "512x512", "type": "image/png" }], "background_color": "#ffffff", "theme_color": "#ffffff", "display": "standalone", - "start_url": "../../" + "start_url": "../" } \ No newline at end of file diff --git a/frontend/src/map/map.ejs b/frontend/src/map/map.ejs index 7e80644f..a9dbb848 100644 --- a/frontend/src/map/map.ejs +++ b/frontend/src/map/map.ejs @@ -2,7 +2,7 @@ - <%= padData && padData.name ? `${padData.name} – ` : ''%>FacilMap + <%= padData && padData.name ? `${padData.name} – ` : ''%><%=appName%> " /> <% if(!padData || (isReadOnly && padData.searchEngines)) { -%> @@ -14,8 +14,8 @@ - - + +