I am working on my first webapp.
I can sign up a user or log in a user and the user is stored in my database and a authentication token is generated when they log in.
I can successfully have the user create a new venture profile which stores in my database and has a foreign key to associate the venture with the user.
So POST is working fine.
I am trying to use GET to send data from the database back to the front end and nothing I do will work. I have checked the code over and over and over and it still seems like the endpoint can't be found.
This is my front end file which is supposed to display users ventures and its just saying "failed to fech user ventures"
async function fetchUserVentures() { try { const token = localStorage.getItem('token'); const response = await fetch('http://localhost:3000/api/ventures', { headers: {'Authorization': `Bearer ${token}` } }); if (!response.ok) { throw new Error('Failed to fetch user ventures'); } const data = await response.json(); userVentures.set(data); } catch (err) { error.set(err.message); } }`
This is from my ventures.js file in routes folder in backend:
router.get('/', authenticateToken, async (req, res) => {try { const ventures = await Venture.findAll({ where: { userId: req.user.userId } }); res.status(200).json(ventures);} catch (error) { console.error('Error fetching ventures:', error.message); res.status(500).json({ error: 'Internal server error' });}});`
I have tried going through the front end files, checking the endpoint and making sure that endpoint exists.It exists. It has the right name, I checked my backend folder and have a routes, models and middleware folder and server.js file and all the files look correct.