#Not implemented: get referrer for Request. Consider calling an action defined in Node.js instead
14 messages · Page 1 of 1 (latest)
Hi @wicked barn. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
The error message "Not implemented: get referrer for Request. Consider calling an action defined in Node.js instead" occurs because Convex's HTTP actions run in a custom JavaScript environment that does not implement all properties and methods of the standard Fetch API's Request object, including request.referrer. This is explicitly mentioned in the error and is consistent with Convex's documentation, which states that HTTP actions do not have access to Node.js-specific APIs and may not fully implement all browser or Node.js features.
If you need access to properties like referrer, you will need to pass that information explicitly from the client (e.g., as a header or query parameter), or, if you require Node.js APIs, you should define an action with the "use node" directive and call it from your HTTP action using ctx.runAction. However, note that HTTP actions themselves cannot be defined in "use node" files and do not run in the Node.js environment—they run in the Convex JS runtime, which is more limited in API support. Only actions (not HTTP actions) can use the Node.js runtime, and you must bridge between them if you need Node.js features in response to an HTTP request Choosing the runtime ("use node") Limits.
In summary:
- request.referrer is not available in Convex HTTP actions.
- To access referrer, pass it explicitly from the client or use a Node.js action and call it from your HTTP action if you need Node.js features.
Your code for extracting the URL and query parameters is correct and will work, but request.referrer will always be undefined in this environment.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@wicked barn Kapa.ai is still learning and improving, please let me know how I did by reacting below.
videoCourseAction defined in actions.js is a HttpAction function. Only actions can be defined in Node.js. See https://docs.convex.dev/functions/actions for more details. @rapid wren
Let me check the knowledge base for you again. One moment! :books:
You are correct: only actions (not HTTP actions) can be defined in Node.js using the "use node" directive. According to the Convex documentation, HTTP actions always run in the default Convex JavaScript runtime, which does not support Node.js-specific APIs or the "use node" directive. If you attempt to define an HTTP action in a file with "use node", or try to use Node.js APIs directly in an HTTP action, you will encounter errors Node.js runtime Limits.
If you need to use Node.js features in response to an HTTP request, the recommended approach is:
- Define your HTTP action in the default runtime (no
"use node"). - Inside your HTTP action, call an action (which can be defined in a
"use node"file) usingctx.runAction.
This way, your HTTP action can handle the HTTP request and delegate any Node.js-specific work to an action running in the Node.js environment.
For more details, see the official documentation on actions and HTTP actions.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@wicked barn Kapa.ai is still learning and improving, please let me know how I did by reacting below.
how to get referrer from httpAction give me full example @rapid wren
Let me check the knowledge base for you again. One moment! :books:
Currently, Convex's HTTP actions do not support accessing the referrer directly via request.referrer or similar properties. This limitation is confirmed by the error message you encountered and is discussed in the knowledge sources: the Convex runtime for HTTP actions does not implement all properties of the standard Request object, including referrer. There is no built-in way to access the referrer header or property from within an httpAction Discord: Not available currently Limits.
Workaround:
If you need the referrer in your Convex HTTP action, you must have the client send it explicitly—either as a custom header or as a query parameter. Here’s how you can do it:
1. Client-side: Send the referrer as a header
fetch("<https://<your-deployment>.convex.site/videoCourse",> {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Referrer": document.referrer // or any value you want to send
},
body: JSON.stringify({ name: "myVideo" })
});
2. Server-side: Read the referrer from the header in your httpAction
import { httpAction } from "./_generated/server";
export const videoCourseAction = httpAction(async (ctx, request) => {
const referrer = request.headers.get("X-Referrer");
const url = new URL(request.url);
const videoName = url.searchParams.get("name");
console.log("referrer:", referrer);
console.log("videoName:", videoName);
// ... your logic here ...
return new Response("OK");
});
Note:
- You cannot access request.referrer directly in Convex HTTP actions.
- You must have the client send the referrer information explicitly if you need it in your Convex backend.
This is the only supported approach according to the current Convex documentation and community discussions Discord: Not available currently Limits.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@wicked barn Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Note for someone need to get referrer from request
here my work-around
let isValidOrigin = false
request.headers.forEach((value, key) => {
if (value.includes(ORIGIN)) {
console.log('found origin:', key, value)
isValidOrigin = true
}
})