Protect API Key in Vue SPA
REST API secrets stay out of Vue / SPA bundles
Vue / SPA cannot safely store REST API production keys. Vault-bound headers reach https://jsonplaceholder.typicode.com/users/{{query.userId}} on Workers while apps call your hide-api-key-vue-spa edge URL.
Why Vue / SPA leaks REST API credentials
Attackers routinely extract REST API secrets from Vue / SPA builds. Direct browser calls also expose internal error payloads with hostnames.
- Production REST API keys copied from Vue / SPA bundles
- Compliance violations after credential leaks
- Attackers replaying vault-grade scopes from a laptop
How RealComposer Solves This at the Edge
Bind vault keys to the Worker
Create API_BEARER_TOKEN vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders.
Set headers, mapping, and cache TTL
Point step upstream at https://jsonplaceholder.typicode.com/users/{{query.userId}} with GET. Add output mapping fields that mirror the JSON contract your screen already expects. Leave cache TTL at 0 when each response is user-specific (include userId or record id in query params before enabling cache).
Call from Vue / SPA
Call https://realcomposer.com/v1/workspace/hide-api-key-vue-spa with a restricted rc_live_ client token. Vue / SPA never sends upstream secrets.
const { data } = await useFetch('https://realcomposer.com/v1/workspace/hide-api-key-vue-spa', {
headers: { Authorization: 'Bearer rc_live_your_token' }
});
{
"requestId": "req_hide-api",
"upstreamLatencyMs": 142,
"audit": {
"region": "edge",
"trace": "hide-api-key-vue-spa"
},
"payload": {
"id": "sample_id",
"status": "active",
"nested": {
"tags": [
"demo"
],
"internal": true
},
"unused_blob": {
"foo": "bar",
"bar": "baz"
}
}
}
{
"userId": "sample",
"name": "sample",
"email": "sample"
}
Recipe Specs
- HTTP method
- GET
- Upstream calls
- 1
- Edge cache TTL
- No caching
- Client auth
- Restricted client token
- Mapped output fields
- 3
- Payload
- 239 B to 52 B (-78%)
curl -X GET "https://realcomposer.com/v1/workspace/hide-api-key-vue-spa" \ -H "Authorization: Bearer rc_live_client_token"
Developer Questions & Troubleshooting
Can Vue / SPA call REST API without holding the production key?
Use scoped tokens where the vendor allows them on hide-api-key-vue-spa. Admin keys stay {{secrets.*}} references only.
How do I forward JSON bodies to POST upstreams?
hide-api-key-vue-spa POST steps bypass caches.default even if cacheTtlSeconds is set in the dashboard.
How do I rotate upstream credentials?
Allowed origins on the hide-api-key-vue-spa client token restrict which domains may call the edge URL.
Sources & Definitions Used in This Answer
Deploy this Vue / SPA + REST API Recipe
Clone this pre-configured pipeline into your RealComposer workspace in one click. We pre-populate upstream URLs, headers, and mapping rules.