Why am I getting Not Found Error in MERN Stack - http-status-code-404

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.)

Related

My request body becomes undefined on frontend side with React

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

Trouble With GitHub Pages

I've seen a few of these posts on StackOverflow already, though I really can't seem to get mine working no matter what I try.
I am trying to host a webpage, though when deploying I am left with a blank screen, and the following error in the console:
Uncaught SyntaxError: Unexpected token '<' in main.e7fa3b75.js:1
I've seen posts which suggest it is a problem with the pathing to my static files, though I cant seem to sort it out.
This post suggests I should remove an extension from my package.json, though I don't use that extension.
This post says I should remove the repository name from the homepage field in the package.json, though that also wouldn't work for me.
I'm out of ideas, here is the repo, if someone doesn't mind taking a look?
I have got it to render the website for a few moments, only to disappear to the same white screen moments later. There are no problems if I run the page on local host.
UPDATE
I have since got the application to host, but only if I explicitly visit the URL of the landing page.
https://jcdw99.github.io/
From the landing page there is a /papers route which can be reached from the navbar. If you press on the button, the page renders. Though, if you try to explicitly view the page, by manually visiting
https://jcdw99.github.io/papers it returns a 404.
Any help?
Try <HashRouter> instead of <BrowserRouter> since Github pages don't support HTML5 history API (see notes on client side routing) but React BrowserRouter uses it. See this question with similar problem.
One observation is if you navigate directly using # in the url, like https://jcdw99.github.io/#/papers it works!

Is there a way to handle URIError in React?

Some days ago I was working on an issue for my job where a page on React couldn't "catch" an error when someone tried to navigate using a bad URL that had the percentage sign (%) that can't be decoded.
The React project uses react-router-dom to handle navigation by showing different views when accessing different URL's (it even has a 404 route when it has no matching routes), and the struture looks very similar to React Router's 404 example, here's the link where you can try for yourself adding /% to the URL from the sandbox's browser and understand in a better way the problem.
In my local-development scenario the page only shows the stack trace in the following image (also check the console output).
I understand that it if someone provides a bad URL that can't be decoded this error will throw and therefore the page will not run. I've been looking for a while and haven't found nothing related to how to catch it on React (I'm not sure if that's really possible).
Any suggestions are welcome!

AdalJs acquireToken fails with invalid state error

My adaljs code to fetch a token for a web api is suddenly failing. This has been working for months now. Since yesterday, I get the following error.
Invalid_state. state: 7ea40a81-5491-47a1-8ebc-89488acb673a|https://sykesenterprises.onmicrosoft.com/MyAPI
This happens when the acquireToken method is called.
I am using the example from https://blog.mastykarz.nl/building-office-365-web-applications-react/ to use react with adaljs.
Managed to sort this out. If anyone else has the same issue, the answer was to just call adal.handleWindowCallback() at the entry point to the application.
The issue occurs because the sample you are referring to needs to be updated as per the latest version of Adal 1.0.16. I was able to fork the repo and submit a pull request to the owner to fix the invalid_state issue. Please refer to the link below to see the code changes:
https://github.com/waldekmastykarz/office-mygroups-react/pull/3/files

FB.getLoginStatus never fires the callback function in Facebook's JavaScript SDK

The simple thing of calling FB.init (right before </body>) and then FB.getLoginStatus(callback) doesn't fire the callback function.
After some debugging, I think the SDK is stuck in the "loading" (i.e. FB.Auth._loadState == 'loading') phase and never gets to "loaded", so all callbacks are queued until the SDK has loaded.
If I force-fire the "loaded" event during debugging - with FB.Event.fire('FB.loginStatus', 'loaded') in case you're intersted - then the callbacks are invoked correctly.
Extra details that might be relevant:
My app is a facebook iframe app (loaded via apps.facebook.com/myapp)
I'm using IE9. The same behavior happens in Chrome
The app is hosted in http://localhost
What's going on? Why is the SDK never gets to loaded?
Thanks
UPDATE: Just tried it on Chrome and it worked (not sure why it didn't work before). Still doesn't work in IE
I had this same problem in Firefox 3.5 on Windows, but only on the very first log in to the page (probably because it was a slower machine and there was some weird timing issues going on).
I fixed it by forcing FB to refresh the login status cookie every time it checks:
FB.getLoginStatus(callback, true); //second argument forces a refresh from Facebook's server.
Without "force=true", sometimes it wouldn't fire the callback.
I had the exact same problem, and I solved it disabling "Secure Browsing" in the Facebook Security settings. Keeping Secure Browsing on forces the pages as "https", but I had no "Secure Canvas URL" set up, and this gave me a lot of errors in the console as well.
Hope this may help someone :)
In my experience, getLoginStatus() never calls the callback in Firefox when third-party cookies are disabled.
The original poster mentioned his application is hosted on http://localhost. I've never had luck with that, and believe it will cause problems.
Just today, I've had problems where getLoginStatus is not calling the callback on any browser, unless the user is actually connected to the app! I'm hoping this is a bug on facebook's end that they will solve.
Yet another possibility for FB.getLoginStatus not firing its callback is when using a "test" user account that has not been authorized to view that application. Its pretty bad that facebook doesn't give you any error messages.
I have also seen failed callbacks on bad appIds and redirectUrls.
I also ran into this issue specifically in Chrome. I tried calling it on page load and after a user-initiated action with no success.
It turned out that it was not a cross-domain issue. The getLoginStatus() call was being blocked by the Un-Passwordise extension in Chrome. As soon as I disabled the extension, it worked perfectly, even on page load.
More info about this issue here: Chrome-only cross-domain scripting errs in Facebook iFrame App upon FB.Login(..)
I understand that this question is a little old now, but I ran across it searching for solutions.
Double-check what you have set in your Facebook app configuration under the section "Website with Facebook Login". The Site URL domain must match the domain your page with the FB.getLoginStatus (and other related auth Javascript) is served from.
After hours of struggling, I realized that I could not reuse an existing app configuration I had on a new server and had to create a new app to handle the website login for this new server.
The other answers are probably equally valid in your specific case, but since there may be others like me who have struggled for a while on this, hopefully this gives you one other place to check. Making a new app with the correct Site URL was the answer in my particular case.

Resources