Post connection works when testing but not on frontend

default discord avatar
takehime
3 months ago
1

I am trying to get a response from a custom API end point that I made though I got


{"errors":[{"message":"The requested resource was not found."}]}


Testing on postman and this doesn't happen, wonder what is the issue. Both the frontend and backend are locally hosted. Am I missing something?



Example code of the Collection


const Sessions: CollectionConfig = {
    slug: 'sessions',
    access: {
        read: () => true,
    }
    // Random field and stuff
    endpoints: [{
        path: '/create'
        method: 'post'
        handler: async (req, res, next) => {
            res.status(200).send({ 
                message: 'Success',
            });
        }
    }]
}


Fetch request is just this (Don't mind the url, unless it is the issue, I am testing this locally first)


await fetch('http://localhost:3000/api/sessions/create', {
    method: 'POST',                
    headers: {
        "Content-Type": "application/json",
    },            
});


Switching to 'get' and it works, though that's not the main issue here. Again, if I send a post request to this endpoint through postman it works as intended.



Nevermind, took me a while to realize I need

credential: 'include'

when sending resquest. This is why you should sleep

    Open the post
    Continue the discussion in Discord
    Like what we're doing?
    Star us on GitHub!

    Star

    Connect with the Payload Community on Discord

    Discord

    online

    Can't find what you're looking for?

    Get help straight from the Payload team with an Enterprise License.