Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
140
rated 0 times [  145] [ 5]  / answers: 1 / hits: 14540  / 3 Years ago, fri, february 26, 2021, 12:00:00

I am using Next.js API routes - https://nextjs.org/docs/api-routes/introduction but I don't know how to protect them from public.


Now those routes are public in my production server.


For example: when I go to mysite.com/api/cats in browser, it returns -


{ success: true, data: [...] }

Please help, how do I hide those API routes from public?


More From » node.js

 Answers
9

If you prevent the browser from requesting the URL then the user won't see the data when they type the URL into the address bar and your JavaScript won't see it when it makes an Ajax request to the same URL.


You can't hide the data from the user of the browser while still allowing your application running in the same browser to access it.


[#1729] Saturday, February 20, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
monetm

Total Points: 615
Total Questions: 103
Total Answers: 119

Location: Finland
Member since Fri, Oct 21, 2022
2 Years ago
monetm questions
;