I am currently learning Node.js (with Express) and so I have a simple API app living on Heroku.
My idea is to have the Node app that's serving my REST API endpoints living on Heroku, provided by a subdomain such as api.example.com
and my frontend living on Vercel with Next.js on the main www.example.com
domain.
How can I secure my api endpoints (not the one's that need login, such as POST
or DELETE
requests but the general GET
requests serving the data that's visible to all users without logging in and to avoid anyone could access my data from my api).
When using e.g. a headless CMS you'll generate an access token you'll add to your frontend app, but how do I best do this? I read about helmet, but not sure if this is enough?
Edit to clarify my needs:
- I want a decoupled backend / frontend setup
- My Node backend is on Heroku and served via api.example.com
- My frontend is using Next.js, running on Vercel and is on the main www.example.com domain
- My app is quite similar to Eventbrite (it is not about events, but has a similar core functionality, so basically a simple CRUD app)
- There are restricted routes where users need to register and login to perform actions such as POST or DELETE requests (e.g. add events, delete events, bookmark events)
- The frontend lists those events and every website visitor can view those events from the home page as well as on dedicated routes, e.g.
/events/id-and-name-of-event
but they need to login if they want to perform various actions (such as delete events if they were added by them or bookmark those events)
What I am afraid of is simply that someone accesses my data from my api and use them on their homepage. That's why I think I need to secure my endpoints to avoid other sites / apps from scraping (from) my api.