0xC0DEGURU
0xC0DEGURU

Reputation: 1792

How to enable CORS in a self-hosted maptiler-server?

I want to configure Access-Control-Allow-Origin of a server machine running maptiler-server but cannot find any documentation how to do it. I also want to know if there is any way to provide the maptiler-serve with access tokens generated by another web server to implement some sort of access control. I don't want the map server to be accessible by everyone. I want to restrict it to the users of a particular web application.

Upvotes: 2

Views: 1313

Answers (1)

0xC0DEGURU
0xC0DEGURU

Reputation: 1792

I found the solution on maptiler's page. Basicly I had to install a reverse proxy that did redirect to the maptiler-server. The example on their page uses Nginx as reverse-proxy server. To configure it in order to add Access-Control-Allow-Origin header on each responses, I had to extend the example with two more lines. So my location block inside configuration file looks like this:

    location / {
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
            proxy_pass http://127.0.0.1:3650;
            proxy_hide_header 'Access-Control-Allow-Origin';
            add_header 'Access-Control-Allow-Origin' '*' always;
    }

The default configuration is located here /etc/nginx/sites-available/ or here /etc/nginx/conf.d/

Upvotes: -1

Related Questions