Repository navigation
feat(water): moneaudebrassage.fr lookup in the web app - #70
Merged
Merged
Conversation
The commune lookup was desktop only, on the assumption that the API rejects cross-origin browser requests and requires an Origin header set to www.moneaudebrassage.fr. Neither holds: the API answers any origin with a matching Access-Control-Allow-Origin, and answers without an Origin header too. A plain GET with Accept: application/json is a simple request, so there is no preflight. The desktop's Origin header never reached the API either: without the unsafe-headers feature, tauri-plugin-http drops forbidden headers and sends the webview origin (tauri://localhost). - Web build uses the browser fetch; desktop keeps the Tauri HTTP plugin. - No Origin header in the request. - The desktop-only notice and the web_unsupported error are gone. Tests: unit tests for the fetch choice and request shape; e2e looks up a commune from Settings with a mocked API (one network fills My water, several show a list to pick from). Checked by hand against the live API from the deployed origin and from a local build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The web app said: "Live commune lookup is available in the desktop app only." The reason given in the code doesn't hold up today:
Access-Control-Allow-Origin, includinghttps://werb-dev.github.io,http://localhost:*andtauri://localhost.Originheader: the API also answers without one. AGETwithAccept: application/jsonis a simple request, so there is no preflight.fetchfrom https://werb-dev.github.io/werb/ in Chromium returned 200 with the data for 73008, 75056, 2A004, 13055 and 69123, and 404 for 00000.The desktop's
Origin: https://www.moneaudebrassage.frheader never reached the API anyway. Without theunsafe-headersfeature,tauri-plugin-httpdrops forbidden headers and sends the webview origin.Change
fetchCommuneAnalyses: browserfetchon the web, Tauri HTTP plugin on desktop, noOriginheader.MabLoader: the INSEE field and network list show everywhere. The desktop-only notice and thewater.mab.web_unsupportederror are removed.The load on moneaudebrassage.fr stays small: one request per click on Load, and the last result is cached.
Tests
page.route, service workers blocked so the route sees the request):