Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

406 and CORS violation when using self-hosted Nominatim #336

Open
oldwired opened this issue Jun 27, 2022 · 6 comments
Open

406 and CORS violation when using self-hosted Nominatim #336

oldwired opened this issue Jun 27, 2022 · 6 comments

Comments

@oldwired
Copy link

When trying to use the plugin with my own instance of nominatim (behind a caddy reverse proxy), which works via browser address bar and Postman, I get the following errors:

geocode.html:1 
        
       Access to XMLHttpRequest at 'https://geocoder.leitstelle.cloud/search?q=Heiligenbreite%206%2C%2088662%20%C3%9Cberlingen&limit=5&format=json&addressdetails=1' from origin 'http://localhost:63342' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
util.ts:109 
 
       GET https://geocoder.leitstelle.cloud/search?q=Heiligenbreite%206%2C%2088662%20%C3%9Cberlingen&limit=5&format=json&addressdetails=1 net::ERR_FAILED 406
getJSON @ util.ts:109
geocode @ nominatim.ts:102
_geocode @ control.ts:336
_keydown @ control.ts:462
o @ DomEvent.js:108

My code:

    var geocoder = L.Control.Geocoder.nominatim(
        {
        serviceUrl: "https://geocoder.leitstelle.cloud/"
    });
    var control = L.Control.geocoder({
        placeholder: 'Search here...',
        geocoder: geocoder
    }).addTo(map);

General:

Request URL: https://geocoder.leitstelle.cloud/search?q=Heiligenbreite%206%2C%2088662%20%C3%9Cberlingen&limit=5&format=json&addressdetails=1
Request Method: GET
Status Code: 406 
Referrer Policy: strict-origin-when-cross-origin

Response Headers:

alternates: {"search.php" 1 {type text/html}}
content-length: 435
content-type: text/html; charset=iso-8859-1
date: Mon, 27 Jun 2022 20:31:18 GMT
server: Caddy
server: Apache/2.4.41 (Ubuntu)
tcn: list
vary: negotiate

Request Headers:

:authority: geocoder.leitstelle.cloud
:method: GET
:path: /search?q=Heiligenbreite%206%2C%2088662%20%C3%9Cberlingen&limit=5&format=json&addressdetails=1
:scheme: https
accept: application/json
accept-encoding: gzip, deflate, br
accept-language: en-GB,en;q=0.9,en-US;q=0.8,de;q=0.7
origin: http://localhost:63342
referer: http://localhost:63342/
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="102", "Microsoft Edge";v="102"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: cross-site
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.124 Safari/537.36 Edg/102.0.1245.44

Like I mentioned, I use a caddy reverse proxy, but that should not matter, because the it also doesn't work if I use a direct connection.
If I let caddy add an Access-Control-Allow-Origin * header I still get the 406 (but not the CORS violation). But when I try postman or the browser access bar for a direct get to the nominatim API the header is already present, so that can't be the problem.

@jakern
Copy link

jakern commented Nov 27, 2022

Hi, is your Nominatim instance still served by Apache behind your reverse proxy?

I encountered a similar issue today and solved it by adding AddType application/json .php to the Apache config.

It seems to be an issue noted in the Nominatim Docker repo already mediagis/nominatim-docker#133

@oldwired
Copy link
Author

oldwired commented Dec 4, 2022

I encountered a similar issue today and solved it by adding AddType application/json .php to the Apache config.

Thanks, works for me. :)

@rooton
Copy link

rooton commented Jan 19, 2023

Unfortunately not work for me. The same error 406.

@oldwired
Copy link
Author

@rooton have you checked the issue mediagis/nominatim-docker#133 ? Looks like it's a problem with the nominatim-docker package

@rooton
Copy link

rooton commented Jan 19, 2023

@oldwired Yes, thats definitely issue with nominatim-docker package. Firstly I have added AddType application/json .php on top of AddType text/html .php and it didn't work, but after moving application/json under text/html it finally worked.

@arshiay
Copy link

arshiay commented Feb 22, 2023

@oldwired Yes, thats definitely issue with nominatim-docker package. Firstly I have added AddType application/json .php on top of AddType text/html .php and it didn't work, but after moving application/json under text/html it finally worked.

hi where you add these line can you explain to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants