Latihan 1: Microservices Architecture — DevOps

Latihan 1 dari materi Microservices Architecture di DevOps — praktek dengan editor kode interaktif, test case otomatis, dan hint terpandu. Langsung jalan di browser.

Buat fungsi routeRequest(gateway, path) yang mensimulasikan API Gateway routing.

gateway adalah object dimana key = path prefix, value = service URL.

Match path prefix terpanjang. Jika tidak ada match, return { error: "no route" }.

Return: { service, path: remaining_path }

Contoh: routeRequest({ "/auth": "http://auth:3001", "/api/orders": "http://orders:3002" }, "/api/orders/123"){ service: "http://orders:3002", path: "/123" }

Hint