mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +00:00
fix(server): judge the address search in the admin status by TREK_PHOTON_URL and an own NOMINATIM_URL
The status asked a fixed Photon origin and compared NOMINATIM_URL with the public address, so a moved Photon or an explicitly set public Nominatim showed the wrong service as in use. It now reads the same photonUrl and nominatimOwn the Photon client decides by. TREK_VALHALLA_URL joins the commented compose variables.
This commit is contained in:
@@ -64,6 +64,7 @@ services:
|
||||
# - TREK_SERVICES=off # Optional. Places search identifies this installation with a key it registers by itself on first use. off sends no key; searches then use the shared pool. (default: auto)
|
||||
# - TREK_SERVICES_KEY= # Optional. A key issued for this installation; it wins over the stored one and turns self-registration off.
|
||||
# - TREK_PHOTON_URL=https://photon.liketrek.com # Optional. The address search of the TREK services. With a key, search and reverse lookups ask it before Nominatim and fall back to Nominatim when it does not answer; never asked when NOMINATIM_URL is set. (default: https://photon.liketrek.com)
|
||||
# - TREK_VALHALLA_URL=https://valhalla.liketrek.com # Optional. The Valhalla of the TREK services, which this server relays routing to unless the admin picks another routing service; the browser never talks to it. (default: https://valhalla.liketrek.com)
|
||||
# - PLACES_API_KEY= # Optional. Google Maps API key (Places API (New) enabled) for place search, photos, details and Google transit. Overrides the key set in Admin > Settings > API Keys, whose field then shows this variable read-only.
|
||||
# - GOOGLE_LIST_DATA_BASE= # Optional. HTTP(S) base URL of a list-data service. Pasted URLs beginning with this base are imported directly; unset keeps the Google flow.
|
||||
# - AMAP_API_KEY= # Optional. Amap (高德地图) Web 服务 key for place search and geocoding inside mainland China. Overrides the key set in Admin > Settings > API Keys. A Web 端 (JS API) key is a different credential and is rejected with INVALID_USER_KEY.
|
||||
|
||||
@@ -1,8 +1,2 @@
|
||||
/** The issuer of installation keys: the Places host itself, so no new egress domain is needed. */
|
||||
export const SERVICE_ISSUER_ORIGIN = 'https://places.liketrek.com';
|
||||
|
||||
/** The TREK services' Photon, the address search that stands in for the public Nominatim. */
|
||||
export const PHOTON_ORIGIN = 'https://photon.liketrek.com';
|
||||
|
||||
/** The Nominatim TREK asks when NOMINATIM_URL names none of the admin's own. */
|
||||
export const PUBLIC_NOMINATIM_URL = 'https://nominatim.openstreetmap.org';
|
||||
|
||||
@@ -5,8 +5,8 @@ import { SettingsService } from '../settings/settings.service';
|
||||
import { IssuerClient } from './issuer.client';
|
||||
import { QuotaTracker } from './quota-tracker';
|
||||
import { ServiceClock } from './service-clock';
|
||||
import { PHOTON_ORIGIN, PUBLIC_NOMINATIM_URL, SERVICE_ISSUER_ORIGIN } from './service-identity.constants';
|
||||
import { isAllowlisted, sameServiceUrl } from './service-identity.helpers';
|
||||
import { SERVICE_ISSUER_ORIGIN } from './service-identity.constants';
|
||||
import { isAllowlisted } from './service-identity.helpers';
|
||||
import { ServiceKeyService, type KeySnapshot } from './service-key.service';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import type { ConfigType } from '@nestjs/config';
|
||||
@@ -77,14 +77,14 @@ export class ServiceIdentityService {
|
||||
}
|
||||
|
||||
private originOf(service: ServiceName): string {
|
||||
if (service === 'photon') return PHOTON_ORIGIN;
|
||||
if (service === 'photon') return this.config.photonUrl;
|
||||
return service === 'valhalla' ? this.config.valhallaUrl : SERVICE_ISSUER_ORIGIN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this instance asks each service right now. Places is in use
|
||||
* whenever the identity is; the other two need the key itself, since they
|
||||
* have no shared pool. Photon stands in for the public Nominatim only, and
|
||||
* have no shared pool. Photon steps aside for an own NOMINATIM_URL, and
|
||||
* the TREK Valhalla answers only where the routing choice comes to it.
|
||||
*/
|
||||
private async servicesInUse(key: KeySnapshot): Promise<Record<ServiceName, boolean>> {
|
||||
@@ -98,7 +98,7 @@ export class ServiceIdentityService {
|
||||
});
|
||||
return {
|
||||
places: true,
|
||||
photon: keyed('photon') && sameServiceUrl(this.env.env().integrations.nominatimUrl, PUBLIC_NOMINATIM_URL),
|
||||
photon: keyed('photon') && !this.env.env().integrations.nominatimOwn,
|
||||
valhalla: routing === 'trek',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -43,7 +43,13 @@ const VIEW = { limit: 50_000, used: 1_234, remaining: 48_766, resetAt: new Date(
|
||||
const writeAudit = vi.fn();
|
||||
let orm: TestOrm;
|
||||
|
||||
type ServicesConfig = { mode: 'auto' | 'off'; key: string | null; hosts: string[]; valhallaUrl: string };
|
||||
type ServicesConfig = {
|
||||
mode: 'auto' | 'off';
|
||||
key: string | null;
|
||||
hosts: string[];
|
||||
photonUrl: string;
|
||||
valhallaUrl: string;
|
||||
};
|
||||
|
||||
async function build(config: Partial<ServicesConfig> = {}) {
|
||||
const moduleRef = await Test.createTestingModule({
|
||||
@@ -54,6 +60,7 @@ async function build(config: Partial<ServicesConfig> = {}) {
|
||||
mode: 'auto',
|
||||
key: null,
|
||||
hosts: ['places.liketrek.com'],
|
||||
photonUrl: 'https://photon.liketrek.com',
|
||||
valhallaUrl: 'https://valhalla.liketrek.com',
|
||||
...config,
|
||||
})
|
||||
|
||||
@@ -29,12 +29,13 @@ const config = {
|
||||
mode: 'auto' as const,
|
||||
key: null,
|
||||
hosts: ['places.liketrek.com'],
|
||||
photonUrl: 'https://photon.liketrek.com',
|
||||
valhallaUrl: 'https://valhalla.liketrek.com',
|
||||
};
|
||||
const ALL_HOSTS = ['places.liketrek.com', 'photon.liketrek.com', 'valhalla.liketrek.com'];
|
||||
const defaults = vi.fn(async (): Promise<Record<string, unknown>> => ({}));
|
||||
const nominatim = { url: 'https://nominatim.openstreetmap.org' };
|
||||
const env = { env: () => ({ integrations: { nominatimUrl: nominatim.url } }) };
|
||||
const nominatim = { own: false };
|
||||
const env = { env: () => ({ integrations: { nominatimOwn: nominatim.own } }) };
|
||||
const VIEW = { limit: 10_000, used: 250, remaining: 9_750, resetAt: new Date(1_793_059_200_000).toISOString() };
|
||||
|
||||
const testDb = createSnapshotTestDb();
|
||||
@@ -44,7 +45,7 @@ let identity: ServiceIdentityService;
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks();
|
||||
config.hosts = ['places.liketrek.com'];
|
||||
nominatim.url = 'https://nominatim.openstreetmap.org';
|
||||
nominatim.own = false;
|
||||
defaults.mockResolvedValue({});
|
||||
issuer.quota.mockResolvedValue({ body: QUOTA, serverMs: null });
|
||||
t = await createTestModule({
|
||||
@@ -174,7 +175,7 @@ describe('ServiceIdentityService.status', () => {
|
||||
|
||||
it('SISVC-009: Photon is not in use beside an own Nominatim, the TREK Valhalla not beside another routing choice', async () => {
|
||||
config.hosts = ALL_HOSTS;
|
||||
nominatim.url = 'https://geocode.example.org';
|
||||
nominatim.own = true;
|
||||
defaults.mockResolvedValue({ valhalla_base_url: 'https://valhalla.example.org' });
|
||||
const status = await identity.status();
|
||||
expect(status.services.map(({ inUse }) => inUse)).toEqual([true, false, false]);
|
||||
|
||||
Reference in New Issue
Block a user