My project rules aren’t applied to the context when I start a chat while editing my file of interest. For example, if I’m editing the test.svelte
file in frontend/src/lib/components/ui/files/
and Cmd+L, the rule is not applied even though the glob in the project rule specifies frontend/**/*.
rule:
---
description: Use when calling backend API endpoints from the frontend
globs: frontend/**/*
---
# Use Backend Helpers in Frontend
When implementing code that needs to call a backend API endpoint, use the callBackend utility function from @backendHelper.ts. This ensures consistent handling of authentication and API requests across the application.
## Pattern
```javascript
// ❌ Don't use fetch directly
const response = await fetch('/api/endpoint', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
// ✅ Do use callBackend utility
import { callBackend } from '@lib/utils/backendHelper';
const response = await callBackend('endpoint', 'POST', data);
```
## Rationale
The callBackend utility:
- Automatically handles authentication tokens
- Ensures consistent API URL prefixing
- Manages common headers
- Provides standardized request formatting
Here’s a screenshot of when it doesn’t work (and I think it should):
When it does work (can’t upload a second screenshot cos new user limits…):
@test.svelte call the backend files api
claude:
I’ll help you create a test.svelte file that calls the backend files API using the proper backend helper pattern. Based on the cursor rules, we should use the callBackend utility function.
<code that calls callBackend as instructed by my rule>