Skip to content

Commit

Permalink
fix(data-service): prevent calling proxying ESRI rest URL twice to en…
Browse files Browse the repository at this point in the history
…sure query params encoding

otherwise first call encodes URL without query params and second call returns unmodified URL, since the host is already the window host
  • Loading branch information
tkohr committed Oct 18, 2023
1 parent ec67fd5 commit 75afa40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 13 additions & 2 deletions libs/feature/dataviz/src/lib/service/data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,22 @@ describe('DataService', () => {
it('builds a proxied url', () => {
expect(
service.getDownloadUrlFromEsriRest(
'http://esri.rest/local/',
'http://esri.rest/local',
'geojson'
)
).toBe(
'http://proxy.local/?url=http%3A%2F%2Fesri.rest%2Flocal%2F%2Fquery%3Ff%3Dgeojson%26where%3D1%3D1%26outFields%3D*'
'http://proxy.local/?url=http%3A%2F%2Fesri.rest%2Flocal%2Fquery%3Ff%3Dgeojson%26where%3D1%3D1%26outFields%3D*'
)
})
it('calls DataFetcher.openDataset with a proxied url', () => {
service.getDataset({
url: new URL('http://esri.rest/local'),
accessServiceProtocol: 'esriRest',
type: 'service',
})
expect(openDataset).toHaveBeenCalledWith(
'http://proxy.local/?url=http%3A%2F%2Fesri.rest%2Flocal%2Fquery%3Ff%3Dgeojson%26where%3D1%3D1%26outFields%3D*',
'geojson'
)
})
})
Expand Down
5 changes: 4 additions & 1 deletion libs/feature/dataviz/src/lib/service/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ export class DataService {
link.type === 'service' &&
link.accessServiceProtocol === 'esriRest'
) {
const url = this.getDownloadUrlFromEsriRest(linkUrl, 'geojson')
const url = this.getDownloadUrlFromEsriRest(
link.url.toString(), //let getDownloadUrlFromEsriRest() proxy url with params
'geojson'
)
return from(openDataset(url, 'geojson')).pipe()
}
return throwError(() => 'protocol not supported')
Expand Down

0 comments on commit 75afa40

Please sign in to comment.