Im trying to send post request from my node.js side. My node file
axios.defaults.baseURL = domain '/api/server';
const getRaffle = () => {
axios.post('/giveaway/getRaffle')
.then(res => {
console.log(res.data)
io.sockets.emit('setRaffle', res.data);
})
.catch(err => {
console.log(err);
});
};
Web.php / api.php (it doesn't work in any of them. when im using api, i know i need to use /api)
Route::group(['prefix' => '/server'], function() {
Route::post('/getRaffle', 'GiveawayController@getRaffle');
});
After this im getting error in terminal: The POST method is not supported for this route. Supported methods: GET, HEAD. Thanks you for help!
CodePudding user response:
In your code example, you're defining a route /server/getRaffle
in api.php routes which means it will have /api/server/getRaffle
URI. But in your Javascript code you're making a request to /api/server/giveaway/getRaffle
. I suggest you double-check that.
You can check all defined routes with php artisan route:list
command. If the route is not listed it's possible your routes are cached in which case you need to run php artisan route:clear
to delete the route cache. Run php artisan route:list
again to see if your route showed up now.
CodePudding user response:
You make a api Post request then you need to set the csrf
token in your request header.