Skip to content

Commit

Permalink
Merge pull request #1025 from geoadmin/feat-PB-871-debug-tools-for-url
Browse files Browse the repository at this point in the history
PB-871 : add debug UI and URL params to override URLs used by data integration team - #minor
  • Loading branch information
pakb committed Aug 27, 2024
2 parents 6842656 + 5061ab6 commit a5e96ae
Show file tree
Hide file tree
Showing 89 changed files with 783 additions and 530 deletions.
9 changes: 5 additions & 4 deletions src/api/features/features.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
ALL_YEARS_TIMESTAMP,
CURRENT_YEAR_TIMESTAMP,
} from '@/api/layers/LayerTimeConfigEntry.class'
import { API_BASE_URL, DEFAULT_FEATURE_COUNT_SINGLE_POINT } from '@/config'
import { getApi3BaseUrl } from '@/config/baseUrl.config'
import { DEFAULT_FEATURE_COUNT_SINGLE_POINT } from '@/config/map.config'
import allCoordinateSystems, { LV95 } from '@/utils/coordinates/coordinateSystems'
import { projExtent } from '@/utils/coordinates/coordinateUtils'
import { createPixelExtentAround } from '@/utils/extentUtils'
Expand Down Expand Up @@ -142,7 +143,7 @@ export async function identifyOnGeomAdminLayer({
}
const imageDisplay = `${screenWidth},${screenHeight},96`
const identifyResponse = await axios.get(
`${API_BASE_URL}rest/services/${layer.getTopicForIdentifyAndTooltipRequests()}/MapServer/identify`,
`${getApi3BaseUrl()}rest/services/${layer.getTopicForIdentifyAndTooltipRequests()}/MapServer/identify`,
{
// params described as https://api3.geo.admin.ch/services/sdiservices.html#identify-features
params: {
Expand Down Expand Up @@ -561,10 +562,10 @@ export const identify = (config) => {
/**
* @param {GeoAdminLayer} layer The layer from which the feature is part of
* @param {String | Number} featureId The feature ID in the BGDI
* @returns {string}
* @returns {String}
*/
function generateFeatureUrl(layer, featureId) {
return `${API_BASE_URL}rest/services/${layer.getTopicForIdentifyAndTooltipRequests()}/MapServer/${layer.id}/${featureId}`
return `${getApi3BaseUrl()}rest/services/${layer.getTopicForIdentifyAndTooltipRequests()}/MapServer/${layer.id}/${featureId}`
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/api/feedback.api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import axios from 'axios'

import { getKmlFromUrl } from '@/api/files.api'
import { API_SERVICES_BASE_URL, APP_VERSION } from '@/config'
import { getViewerDedicatedServicesBaseUrl } from '@/config/baseUrl.config'
import { APP_VERSION } from '@/config/staging.config'
import log from '@/utils/logging'

/** Maximum size allowed by the backend, can be used to do validation up front */
Expand Down Expand Up @@ -48,7 +49,7 @@ export default async function sendFeedback(subject, text, options) {
attachment,
}
log.debug('sending feedback with', data)
const response = await axios.post(`${API_SERVICES_BASE_URL}feedback`, data, {
const response = await axios.post(`${getViewerDedicatedServicesBaseUrl()}feedback`, data, {
headers: {
'Content-Type': 'multipart/form-data',
},
Expand Down
4 changes: 2 additions & 2 deletions src/api/file-proxy.api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'
import { isString } from 'lodash'

import { API_SERVICE_PROXY_BASE_URL } from '@/config'
import { getServiceProxyBaseUrl } from '@/config/baseUrl.config'
import log from '@/utils/logging'

/**
Expand Down Expand Up @@ -29,7 +29,7 @@ export function proxifyUrl(url) {
if (!fileAsPath) {
throw new Error(`Malformed URL: ${url}, can't proxify`)
}
return `${API_SERVICE_PROXY_BASE_URL}${fileAsPath}`
return `${getServiceProxyBaseUrl()}${fileAsPath}`
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/api/files.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import axios, { AxiosError } from 'axios'
import FormData from 'form-data'
import pako from 'pako'

import getFileThroughProxy from '@/api/file-proxy.api.js'
import { API_SERVICE_KML_BASE_URL } from '@/config'
import getFileThroughProxy from '@/api/file-proxy.api'
import { getServiceKmlBaseUrl } from '@/config/baseUrl.config'
import log from '@/utils/logging'

/**
Expand Down Expand Up @@ -67,7 +67,7 @@ export class KmlMetadata {
}
}

const kmlBaseUrl = `${API_SERVICE_KML_BASE_URL}api/kml/`
const kmlBaseUrl = `${getServiceKmlBaseUrl()}api/kml/`

function validateId(id, reject) {
if (!id) {
Expand Down
4 changes: 2 additions & 2 deletions src/api/height.api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'
import proj4 from 'proj4'

import { API_SERVICE_ALTI_BASE_URL } from '@/config'
import { getServiceAltiBaseUrl } from '@/config/baseUrl.config'
import { LV95 } from '@/utils/coordinates/coordinateSystems'
import log from '@/utils/logging'
import { round } from '@/utils/numberUtils'
Expand Down Expand Up @@ -34,7 +34,7 @@ export const requestHeight = (coordinates, projection) => {
// we are giving it LV95 coordinates
const lv95coords = proj4(projection.epsg, LV95.epsg, coordinates)
axios
.get(`${API_SERVICE_ALTI_BASE_URL}rest/services/height`, {
.get(`${getServiceAltiBaseUrl()}rest/services/height`, {
params: {
easting: lv95coords[0],
northing: lv95coords[1],
Expand Down
5 changes: 3 additions & 2 deletions src/api/icon.api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'

import { API_SERVICES_BASE_URL } from '@/config'
import { getViewerDedicatedServicesBaseUrl } from '@/config/baseUrl.config'
import { calculateTextOffset, MEDIUM, RED } from '@/utils/featureStyleUtils'
import log from '@/utils/logging'

Expand Down Expand Up @@ -188,7 +188,8 @@ export async function loadAllIconSetsFromBackend() {
const setPromises = []
const sets = []
try {
const rawSets = (await axios.get(`${API_SERVICES_BASE_URL}icons/sets`)).data.items
const rawSets = (await axios.get(`${getViewerDedicatedServicesBaseUrl()}icons/sets`)).data
.items
for (const rawSet of rawSets) {
const iconSet = new DrawingIconSet(
rawSet.name,
Expand Down
4 changes: 2 additions & 2 deletions src/api/layers/GeoAdmin3DLayer.class.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LayerAttribution } from '@/api/layers/AbstractLayer.class'
import GeoAdminLayer from '@/api/layers/GeoAdminLayer.class'
import LayerTypes from '@/api/layers/LayerTypes.enum'
import { BASE_URL_3D_TILES } from '@/config'
import { get3dTilesBaseUrl } from '@/config/baseUrl.config'

/**
* Metadata for a 3D tile layer (Cesium layer) served by our backend
Expand Down Expand Up @@ -29,7 +29,7 @@ export default class GeoAdmin3DLayer extends GeoAdminLayer {
type: LayerTypes.VECTOR,
technicalName: layerId,
id: layerId,
baseUrl: BASE_URL_3D_TILES,
baseUrl: get3dTilesBaseUrl(),
ensureTrailingSlashInBaseUrl: true,
opacity: 1.0,
visible: true,
Expand Down
4 changes: 2 additions & 2 deletions src/api/layers/GeoAdminVectorLayer.class.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LayerAttribution } from '@/api/layers/AbstractLayer.class'
import GeoAdminLayer from '@/api/layers/GeoAdminLayer.class'
import LayerTypes from '@/api/layers/LayerTypes.enum'
import { VECTOR_TILE_BASE_URL } from '@/config'
import { getVectorTilesBaseUrl } from '@/config/baseUrl.config'

/**
* Metadata for a vector tile layer (MapLibre layer) served by our backend
Expand All @@ -24,7 +24,7 @@ export default class GeoAdminVectorLayer extends GeoAdminLayer {
super({
name: layerId,
type: LayerTypes.VECTOR,
baseUrl: VECTOR_TILE_BASE_URL,
baseUrl: getVectorTilesBaseUrl(),
id: layerId,
technicalName: layerId,
attributions: [
Expand Down
4 changes: 2 additions & 2 deletions src/api/layers/GeoAdminWMSLayer.class.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import GeoAdminLayer from '@/api/layers/GeoAdminLayer.class'
import { InvalidLayerDataError } from '@/api/layers/InvalidLayerData.error'
import LayerTypes from '@/api/layers/LayerTypes.enum'
import { WMS_BASE_URL } from '@/config'
import { getWmsBaseUrl } from '@/config/baseUrl.config'

/**
* Metadata for WMS layer (WMS stands for Web Map Service). It can either be tiled (requested in
Expand Down Expand Up @@ -73,7 +73,7 @@ export default class GeoAdminWMSLayer extends GeoAdminLayer {
opacity = 1.0,
visible = true,
attributions = null,
baseUrl = WMS_BASE_URL,
baseUrl = getWmsBaseUrl(),
format = 'png',
timeConfig = null,
wmsVersion = '1.3.0',
Expand Down
5 changes: 3 additions & 2 deletions src/api/layers/GeoAdminWMTSLayer.class.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import GeoAdminLayer from '@/api/layers/GeoAdminLayer.class'
import { InvalidLayerDataError } from '@/api/layers/InvalidLayerData.error'
import LayerTypes from '@/api/layers/LayerTypes.enum'
import { DEFAULT_GEOADMIN_MAX_WMTS_RESOLUTION, WMTS_BASE_URL } from '@/config'
import { getWmtsBaseUrl } from '@/config/baseUrl.config'
import { DEFAULT_GEOADMIN_MAX_WMTS_RESOLUTION } from '@/config/map.config'
import { TILEGRID_RESOLUTIONS } from '@/utils/coordinates/SwissCoordinateSystem.class'

/**
Expand Down Expand Up @@ -69,7 +70,7 @@ export default class GeoAdminWMTSLayer extends GeoAdminLayer {
format = 'png',
timeConfig = null,
isBackground = false,
baseUrl = WMTS_BASE_URL,
baseUrl = getWmtsBaseUrl(),
isHighlightable = false,
hasTooltip = false,
topics = [],
Expand Down
4 changes: 2 additions & 2 deletions src/api/layers/KMLLayer.class.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AbstractLayer, { LayerAttribution } from '@/api/layers/AbstractLayer.class'
import { InvalidLayerDataError } from '@/api/layers/InvalidLayerData.error'
import LayerTypes from '@/api/layers/LayerTypes.enum'
import { API_SERVICE_KML_BASE_URL } from '@/config'
import { getServiceKmlBaseUrl } from '@/config/baseUrl.config'
import { EMPTY_KML_DATA, parseKmlName } from '@/utils/kmlUtils'

/**
Expand Down Expand Up @@ -48,7 +48,7 @@ export default class KMLLayer extends AbstractLayer {
}
const isLocalFile = !kmlFileUrl.startsWith('http')
const attributionName = isLocalFile ? kmlFileUrl : new URL(kmlFileUrl).hostname
const isExternal = kmlFileUrl.indexOf(API_SERVICE_KML_BASE_URL) === -1
const isExternal = kmlFileUrl.indexOf(getServiceKmlBaseUrl()) === -1
super({
name: 'KML',
id: kmlFileUrl,
Expand Down
2 changes: 1 addition & 1 deletion src/api/layers/WMSCapabilitiesParser.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ExternalWMSLayer, { WMSDimension } from '@/api/layers/ExternalWMSLayer.cl
import { CapabilitiesError } from '@/api/layers/layers-external.api'
import LayerTimeConfig from '@/api/layers/LayerTimeConfig.class'
import LayerTimeConfigEntry from '@/api/layers/LayerTimeConfigEntry.class'
import { WMS_SUPPORTED_VERSIONS } from '@/config'
import { WMS_SUPPORTED_VERSIONS } from '@/config/map.config'
import allCoordinateSystems, { WGS84 } from '@/utils/coordinates/coordinateSystems'
import log from '@/utils/logging'

Expand Down
10 changes: 5 additions & 5 deletions src/api/layers/layers.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import GeoAdminWMSLayer from '@/api/layers/GeoAdminWMSLayer.class'
import GeoAdminWMTSLayer from '@/api/layers/GeoAdminWMTSLayer.class'
import LayerTimeConfig from '@/api/layers/LayerTimeConfig.class'
import LayerTimeConfigEntry from '@/api/layers/LayerTimeConfigEntry.class'
import { API_BASE_URL, DEFAULT_GEOADMIN_MAX_WMTS_RESOLUTION, WMTS_BASE_URL } from '@/config'
import { getApi3BaseUrl } from '@/config/baseUrl.config'
import { DEFAULT_GEOADMIN_MAX_WMTS_RESOLUTION } from '@/config/map.config'
import log from '@/utils/logging'

// API file that covers the backend endpoint http://api3.geo.admin.ch/rest/services/all/MapServer/layersConfig
Expand Down Expand Up @@ -83,7 +84,6 @@ const generateClassForLayerConfig = (layerConfig, id, allOtherLayers, lang) => {
format,
timeConfig,
isBackground: !!isBackground,
baseUrl: WMTS_BASE_URL,
isHighlightable,
hasTooltip,
topics,
Expand Down Expand Up @@ -209,7 +209,7 @@ const generateClassForLayerConfig = (layerConfig, id, allOtherLayers, lang) => {
export const getLayerDescription = (lang, layerId) => {
return new Promise((resolve, reject) => {
axios
.get(`${API_BASE_URL}rest/services/all/MapServer/${layerId}/legend?lang=${lang}`)
.get(`${getApi3BaseUrl()}rest/services/all/MapServer/${layerId}/legend?lang=${lang}`)
.then((response) => resolve(response.data))
.catch((error) => {
log.error('Error while retrieving the legend for the layer', layerId, error)
Expand All @@ -226,13 +226,13 @@ export const getLayerDescription = (lang, layerId) => {
*/
export const loadLayersConfigFromBackend = (lang) => {
return new Promise((resolve, reject) => {
if (!API_BASE_URL) {
if (!getApi3BaseUrl()) {
// this could happen if we are testing the app in unit tests, we simply reject and do nothing
reject('API base URL is undefined')
} else {
const layersConfig = []
axios
.get(`${API_BASE_URL}rest/services/all/MapServer/layersConfig?lang=${lang}`)
.get(`${getApi3BaseUrl()}rest/services/all/MapServer/layersConfig?lang=${lang}`)
.then(({ data: rawLayersConfig }) => {
if (Object.keys(rawLayersConfig).length > 0) {
Object.keys(rawLayersConfig).forEach((rawLayerId) => {
Expand Down
12 changes: 8 additions & 4 deletions src/api/print.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ import {
import axios from 'axios'
import { Circle } from 'ol/style'

import { API_BASE_URL, API_SERVICES_BASE_URL, WMS_BASE_URL } from '@/config'
import {
getApi3BaseUrl,
getViewerDedicatedServicesBaseUrl,
getWmsBaseUrl,
} from '@/config/baseUrl.config'
import i18n from '@/modules/i18n'
import log from '@/utils/logging'
import { adjustWidth } from '@/utils/styleUtils'

const PRINTING_DEFAULT_POLL_INTERVAL = 2000 // interval between each polling of the printing job status (ms)
const PRINTING_DEFAULT_POLL_TIMEOUT = 600000 // ms (10 minutes)

const SERVICE_PRINT_URL = `${API_SERVICES_BASE_URL}print3/print/mapviewer`
const SERVICE_PRINT_URL = `${getViewerDedicatedServicesBaseUrl()}print3/print/mapviewer`
const MAX_PRINT_SPEC_SIZE = 1 * 1024 * 1024 // 1MB in bytes (should be in sync with the backend)

class GeoAdminCustomizer extends BaseCustomizer {
Expand Down Expand Up @@ -342,7 +346,7 @@ async function transformOlMapToPrintParams(olMap, config) {
})
if (printGrid) {
encodedMap.layers.unshift({
baseURL: WMS_BASE_URL,
baseURL: getWmsBaseUrl(),
opacity: 1,
singleTile: true,
type: 'WMS',
Expand Down Expand Up @@ -377,7 +381,7 @@ async function transformOlMapToPrintParams(olMap, config) {
classes: layersWithLegends.map((layer) => {
return {
name: layer.name,
icons: [`${API_BASE_URL}static/images/legends/${layer.id}_${lang}.png`],
icons: [`${getApi3BaseUrl()}static/images/legends/${layer.id}_${lang}.png`],
}
}),
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/profile/profile.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import proj4 from 'proj4'

import ElevationProfile from '@/api/profile/ElevationProfile.class'
import ElevationProfileSegment from '@/api/profile/ElevationProfileSegment.class'
import { API_SERVICE_ALTI_BASE_URL } from '@/config'
import { getServiceAltiBaseUrl } from '@/config/baseUrl.config'
import { LV95 } from '@/utils/coordinates/coordinateSystems'
import { removeZValues, unwrapGeometryCoordinates } from '@/utils/coordinates/coordinateUtils.js'
import log from '@/utils/logging'
Expand Down Expand Up @@ -85,7 +85,7 @@ export async function getProfileDataForChunk(chunk, startingPoint, startingDist,
if (chunk.isWithinBounds) {
try {
const dataForChunk = await axios({
url: `${API_SERVICE_ALTI_BASE_URL}rest/services/profile.json`,
url: `${getServiceAltiBaseUrl()}rest/services/profile.json`,
method: 'POST',
params: {
offset: 0,
Expand Down
4 changes: 2 additions & 2 deletions src/api/qrcode.api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'

import { API_SERVICES_BASE_URL } from '@/config'
import { getViewerDedicatedServicesBaseUrl } from '@/config/baseUrl.config'
import log from '@/utils/logging'

/**
Expand All @@ -11,7 +11,7 @@ import log from '@/utils/logging'
*/
export function getGenerateQRCodeUrl(url) {
const encodedUrl = encodeURIComponent(url)
return `${API_SERVICES_BASE_URL}qrcode/generate?url=${encodedUrl}`
return `${getViewerDedicatedServicesBaseUrl()}qrcode/generate?url=${encodedUrl}`
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/api/search.api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'
import proj4 from 'proj4'

import { API_SERVICE_SEARCH_BASE_URL } from '@/config'
import { getServiceSearchBaseUrl } from '@/config/baseUrl.config'
import CoordinateSystem from '@/utils/coordinates/CoordinateSystem.class'
import { LV95, WGS84 } from '@/utils/coordinates/coordinateSystems'
import CustomCoordinateSystem from '@/utils/coordinates/CustomCoordinateSystem.class'
Expand Down Expand Up @@ -95,7 +95,7 @@ export function sanitizeTitle(title = '') {
* @returns Promise<Array<Any>>
*/
const generateAxiosSearchRequest = (query, lang, type, cancelToken, extraParams = {}) => {
return axios.get(`${API_SERVICE_SEARCH_BASE_URL}rest/services/ech/SearchServer`, {
return axios.get(`${getServiceSearchBaseUrl()}rest/services/ech/SearchServer`, {
cancelToken,
params: {
sr: LV95.epsgNumber,
Expand Down
4 changes: 2 additions & 2 deletions src/api/shortlink.api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'

import { API_SERVICE_SHORTLINK_BASE_URL } from '@/config'
import { getServiceShortLinkBaseUrl } from '@/config/baseUrl.config'
import log from '@/utils/logging'

/**
Expand All @@ -26,7 +26,7 @@ export function createShortLink(url, withCrosshair = false) {
reject(errorMessage)
}
axios
.post(API_SERVICE_SHORTLINK_BASE_URL, {
.post(getServiceShortLinkBaseUrl(), {
url: sanitizedUrl,
})
.then((response) => {
Expand Down
Loading

0 comments on commit a5e96ae

Please sign in to comment.