My request body becomes undefined on frontend side with React - reactjs

I'm heading here today because I have a problem that I can't seem to solve, and I don't see where the error is. I'm developing a corporate social network, so far so good. Now I'm trying to implement a comment space for posts and that's where it's bugging. I establish my function to create a back side comment (with nodeJs and express) which is:
Function commentaire back
When I run this back function with postman everything goes fine and the comment is created.
commenter with postman
But on the other hand when I execute this function on the front side (with React) my request body becomes undefined while I use the exact same function to create a post and it works very well. Here is the run function on the front side:
Fonction commentaire front
and the response I get:
commenter with React
And also what I get in the console:
console
So I already tried to remove the required: true from the information but that didn't change anything, and then as I said before I used the exact same syntax on the back and front side for the function that creates a new post and it works very well.
If someone can enlighten me, I really can't see what's stuck.
Thanks in advance

Related

API fetching didn't work after I deployed

I deployed my React web work as a test at Vercel but the API didn't work and my web now is Empty..
my project and api works perfectly in my localhost !
some one knows why ?
my empty web :-
https://web-3-0-prokect-1.vercel.app/
api code in the useEffect hook:-
https://github.com/Adelndf/web.3.0-prokect-1/blob/master/src/App.js
by the way im new in coding so some of my coding words or terms might be little bit weird :)
hopefully someone understand my issue here
Your API request is not successful because of CORS error. This usually won't be an issue when you try in localhost. To learn more about CORS, click here.
I fixed it with the easy way cuz at the end its just a testing project..
the solution if any one needed it is :-
i added ( https://cors-anywhere.herokuapp.com/ ) before my api ulr and it works..
u can see it in github link at the top

Why am I getting Not Found Error in MERN Stack

i am having a problem connecting to backend
whenever i click submit button, i am getting a 404 error. clicking submit button must redirect to localhost:5000/posts
i am getting the error from 3 sites from my client side:
https://github.com/Yokubjon-J/posts-mern-stack/blob/master/client/src/api/index.js#L5
https://github.com/Yokubjon-J/posts-mern-stack/blob/master/client/src/actions/posts.js#L17
https://github.com/Yokubjon-J/posts-mern-stack/blob/master/client/src/components/Form/Form.js#L17
any suggestions?
i even included proxy in package.json file but it wasn't helpful
Due to the help from online community, I realized that the mistake was in server/routers/post.js file where i typed router.get('/', createPost);, i changed it to router.post('/', createPost); and my problem was solved by it.
A helpful comment by a member of online community:
If you get 404 with an endpoint that should exists, usually it means you've either used the wrong method - eg get instead of post - or you haven't connected your router to your app. (If other end points work for the router then it's unlikely the latter.)

Which parts of the ImgurV3 API can be used anonymously?

The documentation says:
For public read-only and anonymous resources, such as getting image info, looking up user comments, etc. all you need to do is send an authorization header with your client_id in your requests. This also works if you'd like to upload images anonymously (without the image being tied to an account), or if you'd like to create an anonymous album. This lets us know which application is accessing the API.
But it's not clear what the "etc." part includes. It's not clearly defined in the documentation. I have been using Postman to debug before putting this down in AngularJS -- this is just an AngularJS learning project for me -- and I can't get things like the gallery images for a particular subreddit. I get a status 403 back.
Anyone ever done this before?
As it turns out, if you register for an API key it doesn't take effect right away. The API key you get may not work for a few hours. (I'm guessing this is worst-case.)
It works now, with the exact same code and no changes.

AngularJS $http not sending GET request

In an Angular JS app I'm working on, I am using a service to periodically (in a $timeout) make a GET request to a URL in my API (both the Angular app and the API are being served from port 5000 on localhost).
For some reason, it appears that $http is not actually sending the GET. For each $http.get(), the .error() is called with empty data and a status of 0. When I check in my server log (I'm running a Ruby on Rails backend with the Unicorn gem for my server), it appears that the server never receives the request from Angular.
Here's the function in my service:
updateUserStatus = () ->
$http.get('/api/v1/status').success (statusData) ->
# update the variable and notify the observers
this.userStatus = statusData
notifyObservers()
startStatusTimeout()
.error (error, status) ->
# if there's an error, log it
console.log 'error:'
console.log error
console.log status
startStatusTimeout()
What's really odd is that it only happens sometimes. When it stops working, I can change the URL in the $http.get() to '/api/v1/status.json', and it works. For a while. Then I switch it back and it works again, for a while... obviously there is some greater issue at play.
I've been racking my brain for a few days now, and I've seen a bunch of similar issues on SO, but they all seem to be solved with implementing CORS in Angular, which I don't think is applicable to my situation because it's all coming from localhost:5000. Am I wrong? What's going on?
For reference, I'm using Angular version 1.0.7.
I had the same problem.
Check your code to see whether this happens after events that are fired from the DOM and are unknown to Angular.
If so, you need to add $scope.$apply(); after the get request in order to make it happen.
I'm fairly new to Angular so I'm not sure this is the best practice for using Angular, but it did work in my case.
See this similar question for a better explanation.

Channel API - sometimes I don't get message

I noticed that every createchannel() replaces the iFrame url.
Is there any chance that due to a re-call to createChannel() my iFrame is being replaced by new iFrame BUT the binding between the clientID and the iFrame url wasn't updated?
For example:
I called "channel.create_channel(unique_id)" - and I got back the JS with 123.talkgadget.google....as an iFrame.
Then,
I called again with the same client id "channel.create_channel(unique_id)" - and I got back the JS with 456.talkgadget.google....as an iFrame.
Is there any chance that if I call now "channel.send_message(unique_id,msg)"
the message will be sent to 123.talkgadget.google instead of 456.talkgadget.google resulting that I didn't get the message?
Thanks!
I'm not 100% certain about this answer. I haven't tested thoroughly, it's a little hard to test since the dev_appserver behavior is quite different from the real server behavior.
I believe I have seen this behavior before (missing messages).
If you close the old channel from the client side it seems to make everything work properly.
I have not tried handling the case where you lose your internet connection and you can't close from the client side though.

Resources