diff --git a/api/config/settings/common.py b/api/config/settings/common.py index d71992be1..3f7cc7503 100644 --- a/api/config/settings/common.py +++ b/api/config/settings/common.py @@ -313,7 +313,8 @@ REST_FRAMEWORK = { } ATOMIC_REQUESTS = False - +USE_X_FORWARDED_HOST = True +USE_X_FORWARDED_PORT = True # Wether we should check user permission before serving audio files (meaning # return an obfuscated url) # This require a special configuration on the reverse proxy side diff --git a/api/funkwhale_api/music/serializers.py b/api/funkwhale_api/music/serializers.py index 40fbb65ea..744115f86 100644 --- a/api/funkwhale_api/music/serializers.py +++ b/api/funkwhale_api/music/serializers.py @@ -31,11 +31,20 @@ class ImportBatchSerializer(serializers.ModelSerializer): model = models.ImportBatch fields = ('id', 'jobs', 'status', 'creation_date') + class TrackFileSerializer(serializers.ModelSerializer): + path = serializers.SerializerMethodField() + class Meta: model = models.TrackFile fields = ('id', 'path', 'duration', 'source', 'filename') + def get_path(self, o): + request = self.context.get('request') + url = o.path + if request: + url = request.build_absolute_uri(url) + return url class SimpleAlbumSerializer(serializers.ModelSerializer): diff --git a/deploy/nginx.conf b/deploy/nginx.conf index 6a0a9f509..a85230ae8 100644 --- a/deploy/nginx.conf +++ b/deploy/nginx.conf @@ -41,6 +41,8 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host:$server_port; + proxy_set_header X-Forwarded-Port $server_port; proxy_redirect off; proxy_pass http://funkwhale-api/api/; } diff --git a/dev.yml b/dev.yml index f0fc8845a..78bf76fcd 100644 --- a/dev.yml +++ b/dev.yml @@ -63,4 +63,4 @@ services: - ./docker/nginx/conf.dev:/etc/nginx/nginx.conf - ./api/funkwhale_api/media:/protected/media ports: - - "0.0.0.0:6001:80" + - "0.0.0.0:6001:6001" diff --git a/docker/nginx/conf.dev b/docker/nginx/conf.dev index 6ca395fb1..9c00fd76f 100644 --- a/docker/nginx/conf.dev +++ b/docker/nginx/conf.dev @@ -28,7 +28,7 @@ http { #gzip on; server { - listen 80; + listen 6001; charset utf-8; location /_protected/media { @@ -40,6 +40,8 @@ http { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host:$server_port; + proxy_set_header X-Forwarded-Port $server_port; proxy_redirect off; proxy_pass http://api:12081/; }