The K8M frontend uses a custom fetcher (defined in ui/src/components/Amis/fetcher.ts) to wrap all HTTP requests. This fetcher is automatically injected into the AMIS rendering process.
Key Features
- Automatic Authentication: Automatically adds
Authorization: Bearer ${token} from localStorage to every request. - Cluster Context Injection: Automatically handles cluster URL rewriting. It supports specifying a target cluster via the
x-k8m-target-cluster header or the __cluster query parameter. - Error Handling:
401: Automatically redirects to /#/login.512: Indicates insufficient cluster permissions; redirects to cluster user management.403: Indicates insufficient permissions.
Usage in AMIS Schema
When defining an AMIS component, the api field will automatically use this fetcher:
{
"type": "crud",
"api": {
"method": "get",
"url": "/k8s/cluster/${cluster}/pods"
}
}
renderAmis(schema, initialData, {
theme: 'cxd',
fetcher, // Injected custom fetcher
isCancel: value => axios.isCancel(value),
})