| 808 | } |
| 809 | |
| 810 | func (s *HttpServer) parseUrlPath( |
| 811 | r *http.Request, |
| 812 | preSelectedProjectId, |
| 813 | preSelectedArchitecture, |
| 814 | preSelectedChainId string, |
| 815 | ) ( |
| 816 | projectId, architecture, chainId string, |
| 817 | isAdmin bool, |
| 818 | isHealthCheck bool, |
| 819 | err error, |
| 820 | ) { |
| 821 | ps := path.Clean(r.URL.Path) |
| 822 | segments := strings.Split(ps, "/") |
| 823 | |
| 824 | // Remove empty first segment from leading slash |
| 825 | segments = segments[1:] |
| 826 | |
| 827 | isPost := r.Method == http.MethodPost |
| 828 | isOptions := r.Method == http.MethodOptions |
| 829 | |
| 830 | // Initialize with preselected values |
| 831 | projectId = preSelectedProjectId |
| 832 | architecture = preSelectedArchitecture |
| 833 | chainId = preSelectedChainId |
| 834 | |
| 835 | // Special case for admin endpoint |
| 836 | if len(segments) == 1 && segments[0] == "admin" && (isPost || isOptions) { |
| 837 | return "", "", "", true, false, nil |
| 838 | } |
| 839 | |
| 840 | // Handle healthcheck variations |
| 841 | if len(segments) > 0 && segments[len(segments)-1] == "healthcheck" { |
| 842 | isHealthCheck = true |
| 843 | segments = segments[:len(segments)-1] // Remove healthcheck segment |
| 844 | } else if len(segments) == 0 || (len(segments) == 1 && segments[0] == "") { |
| 845 | if !(isPost || isOptions) { |
| 846 | isHealthCheck = true |
| 847 | segments = nil |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | // Parse remaining segments based on what's preselected |
| 852 | switch { |
| 853 | case projectId == "" && architecture == "" && chainId == "": |
| 854 | // Case: Nothing preselected |
| 855 | switch len(segments) { |
| 856 | case 1: |
| 857 | projectId = segments[0] |
| 858 | case 2: |
| 859 | projectId = segments[0] |
| 860 | // Check if second segment is a network alias |
| 861 | if project, err := s.erpc.GetProject(projectId); err == nil { |
| 862 | architecture, chainId = project.networksRegistry.ResolveAlias(segments[1]) |
| 863 | } |
| 864 | if architecture == "" { |
| 865 | architecture = segments[1] |
| 866 | } |
| 867 | case 3: |