Panduan GCP Professional Cloud Architect & Full Stack: Menyajikan Apple Universal Links (AASA) di Google Cloud Run & Django

Spesialisasi Rekayasa Perangkat Lunak: Ditulis oleh Aldian Fazrihady — Senior Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend Engineer, AI Application Engineer & Full Stack Engineer.

1. Mengapa Apple CDN Bot Gagal Memvalidasi File AASA pada Aplikasi Django Multi-Bahasa di Cloud Run?

Saat mengintegrasikan iOS Universal Links dan Shared Web Credentials dengan backend Django yang berjalan di Google Cloud Run, crawler validasi Apple (AASA-Bot/1.0.0) mengambil URL https://domain/apple-app-site-association dan https://domain/.well-known/apple-app-site-association. Jika rute tersebut diletakkan di dalam i18n_patterns Django atau mengembalikan 301/302 Redirect, Apple akan langsung menolak verifikasi domain.

2. Konfigurasi Rute Root Django, Header application/json, dan Google Cloud Run

Sebagai GCP Professional Cloud Architect dan Full Stack Engineer, pastikan rute .well-known/apple-app-site-association didaftarkan di luar i18n_patterns dengan header Content-Type: application/json tanpa ekstensi .json. Berikut adalah implementasi lengkapnya di Django dan Cloud Run:

from django.http import JsonResponse
from django.views.decorators.cache import cache_page
from django.utils.decorators import method_decorator
from rest_framework.views import APIView
from rest_framework.permissions import AllowAny

class AppleSiteAssociationView(APIView):
    """
    Serves the Apple App Site Association (AASA) file for Universal Links.
    """
    permission_classes = [AllowAny]  # Publicly accessible

    @method_decorator(cache_page(3600))  # Cache for 1 hour to reduce database hits
    def get(self, request, *args, **kwargs):
        # Your Apple Developer credentials
        team_id = "ABC123DEF"
        bundle_id = "com.therandiguys.app"

        aasa_payload = {
            "applinks": {
                "apps": [],
                "details": [
                    {
                        "appID": f"{team_id}.{bundle_id}",
                        "paths": ["*"]  # Support deep linking to all paths
                    }
                ]
            },
            "webcredentials": {
                "apps": [f"{team_id}.{bundle_id}"]
            },
            "appclips": {
                "apps": [f"{team_id}.{bundle_id}.Clip"]
            }
        }
        
        # Explicitly set the Content-Type to application/json
        return JsonResponse(aasa_payload, content_type="application/json")
from django.urls import path
from api.views.apple_site_association import AppleSiteAssociationView

urlpatterns = [
    # Map the AASA view at its expected path
    path('.well-known/apple-app-site-association', AppleSiteAssociationView.as_view(), name='aasa_root'),
    path('apple-app-site-association', AppleSiteAssociationView.as_view(), name='aasa_legacy'),
]
curl -H "Accept: application/json" https://app.yourdomain.com/.well-known/apple-app-site-association
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
        if let webpageURL = userActivity.webpageURL {
            // Parse URL and route the user inside your Swift UI
            print("Successfully intercepted deep link: \(webpageURL)")
            return true
        }
    }
    return false
}

Ringkasan Arsitektur Produksi & Praktik Terbaik (Checklist Teknis)


About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)

Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 15+ years of production software engineering experience.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD / Rp 1.000.000) | View Live AI Portfolio | Send a Direct Message

Related Engineering Articles

Engineering Role Pillar Guides & Category Hubs