kapa.ai
BOT
— Today at 12:52 PM
Let me check the knowledge base for you. One moment! 📚
The URL is visible because it's being logged to the console. If you don't want users to see the URL, you should remove or comment out any console.log statements that print the URL or the fetched data to the console.
However, if you're referring to the network requests being visible in the browser's developer tools, this is something that can't be avoided. When you make a fetch request in the browser, it's a network request that's visible in the developer tools network tab. This is a feature of the browser and there's no way to hide this from users who know how to use these tools.
If you want to completely hide the API endpoint from the client, you could create a server-side function (in Next.js, this would be an API Route) that makes the fetch request to the API endpoint. Your client-side code would then make a request to this server-side function, and all the client would see is the request to your server-side function, not the actual API endpoint.
Here's an example of how you can create a server-side function in Next.js:
// pages/api/tracking.js
export default async function handler(req, res) {
const no_resi = req.query.no_resi;
const response = await fetch(
<https://url.com/api/trackingpermember/${no_resi}/,>
{
headers: {
Authorization: Bearer ${process.env.ANTR_TOKEN},
},
}
);
const data = await response.json();
res.status(200).json(data);
}
Then, in your client-side code, you would fetch data from this server-side function instead of the actual API endpoint:
const res = await fetch(/api/tracking?no_resi=${trackingNumber});
const data = await res.json();
In this example, the client only sees a request to /api/tracking, and the actual API endpoint is hidden in the server-side function.
Note: you can ask me a follow up question by @ mentioning me again 💬
@raw mango
I am using the new app router
Do i need to name it page.tsx like other?
Can you help me structure and name it properly?