trying to pass pathname in the get func
Answered
Citrine Wagtail posted this in #help-forum
Citrine WagtailOP
useEffect(() => {
const WorkingDir = async () => {
try {
const ipResponse = await axios.get(
"/api/test",
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
await GET(ipResponse.request, user, pathname);
} catch (error) {}
console.log(pathname);
};this is where i called the api and passing the pathname to the func but i am getting undefined
export async function GET(request: Request, user: any, pathname: string) {
try {
const ip =
request.headers.get("x-forwarded-for") ||
request.headers.get("x-real-ip");
if (!ip) {
console.error("Unable to get IP address");
return new Response("Unable to get IP address", { status: 400 });
}
const count = ipAddresses.get(ip) || 0;
ipAddresses.set(ip, count + 1);
const content = Array.from(ipAddresses.entries())
.map(
([ip, count], index) =>
`${index + 1}. IP: ${ip} | Count: ${count} | User ID: ${
user.uid
} | Pathname: ${pathname}`
)
.join("\n");
const message = `Enigma Main\n\n${content}`;
// Send the content to Discord
try {
await axios.post(DISCORD_WEBHOOK_URL, {
content: `\`\`\`${message}\`\`\``,
});
} catch (error) {
return new Response("Error Connecting with main", { status: 500 });
}
return new Response(`Websocket Connected succesfully.`);
} catch (error) {
console.error("Error in GET function:", error);
return new Response("Internal Server Error", { status: 500 });
}
}this is the route for the api
Answered by Citrine Wagtail
nevermind i found a solution just need to do post instead of get and pass the the user uid and pathname in the body
3 Replies
Citrine WagtailOP
Hey guys any sol for this?
Citrine WagtailOP
anyone can help me please ?
Citrine WagtailOP
nevermind i found a solution just need to do post instead of get and pass the the user uid and pathname in the body
Answer