Returning a 404 Error stating "Invalid request to /api/users/register."

Encountering an issue with proxy connection - unable to determine the root cause despite verifying all routes. Not able to successfully register the user and store data in MongoDB. Seeking suggestions for resolution. Thank you.

Attempting to send user registration data via POST to http://localhost:3000/api/users/register results in a 404 (Not Found) error. Any insights on resolving this issue would be appreciated.

POST http://localhost:3000/api/users/register 404 (Not Found)
Error: Request failed with status code 404
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.onloadend (xhr.js:66)

Answer №1

It doesn't seem like a configuration issue or a problem with the proxy.

The issue lies in your server.js file, specifically in the route request section.

To resolve this, update the route to

app.use('/api/users', usersRoute)

instead of

app.use('/api/rooms', roomsRoute)
app.use('api/users', usersRoute)

This will ensure that the link you are trying to access is sent as a post request to the backend.

Error 404 typically indicates a syntax error. Verify the syntax before checking the configuration file.

Answer №2

The default port for the API server is set to 5000, but the frontend app is trying to connect on port 3000.

Ensure that you are making API calls using the correct port number.

  • If there are proxy issues, consider changing the API to a full URL like:
"proxy": {
    "/api/users": {
        "target": "http://localhost:5000"
    }
},

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The function for the "load next page" action in ngInfiniteScroll is continuously triggered

After attempting to implement infinite scrolling using the "loading remote data" example from the ngInfiniteScroll website, I am facing a problem. The function nextPage() is being called continuously until all records have been loaded (controlled by an of ...

I am unable to get the radio button checked in Angular 2

I have set up a form with two radio buttons for gender selection, and I want to ensure that the previously selected option is displayed as checked. Here's the code snippet I've added in my template: <div class="form-group"> <label& ...

"Encountering issue with React failing to display background images when called from

One of my components (actually a function) utilizes a parameter for specifying a background image: const Card = function(image){ return( <div className="card" style={{backgroundImage: 'url(../../static/assets/' + ima ...

Sharing precise API information between React components in React Components

I am currently learning react and facing an issue with sending data to other component files. I am trying to verify a user login from a backend API within an if statement, and if successful, I want to send the user ID to another component file. However, ...

Is there a way to ensure that a certain block of code in Typescript is executed only after an API call has been completed?

When making an API call, I need the code after the call to wait until the API call finishes. In my function called this.api_call, it calls the API and only returns an array returnValue once the call is complete. let returnValue = this.api_call(data); // ...

Navigating different domains in ExpressJS - Handling CORS

Currently, I am facing a challenge in setting the domain for a cookie that I am sending along with the response from my ExpressJS implementation. Unfortunately, at the moment, it is only being set to the IP address of where my ExpressJS server is located. ...

Analyze React.js source code for errors, instead of focusing solely on the DOM manipulation aspect

Can breakpoints be set in React.js code and debugged in the actual script rather than just in compiled javascript? For example: var HelloMessage = React.createClass({ render: function() { return <div>Hello {this.props.name}</div>; // ...

Design a TypeScript interface inspired by a set static array

I am working with an array of predefined strings and I need to create an interface based on them. To illustrate, here is an example of pseudo-interfaces: const options = ["option1", "option2", "option3"]; interface Selection { choice: keyof options; ...

Sending data from MongoDB API to HTML in Electron using parameters

I am currently developing an Electron application for my personal use and utilizing MongoDB Atlas as the backend for my Node application. As I am relatively new to Electron, I am still experimenting with different approaches, so there might be some minor m ...

Showcasing PHP variables within HTML using jQuery

I am currently looking for the best way to showcase information stored in a PHP variable, retrieved from a MySQL database. My initial thought was to use jQuery. Here are my questions: When a user inputs a number into a field, I receive that Member' ...

Encountering an issue when deploying a project using node, webpack, express, and mysql to Heroku. The error message states: "Uncaught ReferenceError: regeneratorRuntime is not

I've been going around in circles ever since I started this project, and now the code is all over the place. This is my first time working on a node project without using a framework, and I'm starting to regret not choosing PHP. Anyway, here&apos ...

The command specified in the package.json "bin" could not be located by npx

I created a basic Node.js TypeScript application with two executable entries in the bin property of its package.json file. Here is an example of the package.json content: { "name": "test-npx-command", "version": " ...

Tips for creating an Enumerable 'similarity' search using linq.js

I have a JSON array that looks like this: [ { "_Id": "0001", "_PatentId": "0000", "_Text": "Employee", "_Value": "employee", "_PermissionLevel": 55 }, { "_Id": "0002", "_PatentId": "0000", "_Text": "Employees" ...

Do you have an index.d.ts file available for canonical-json?

I am currently working on creating an index.d.ts file specifically for canonical-json. Below is my attempted code: declare module 'canonical-json' { export function stringify(s: any): string; } I have also experimented with the following sn ...

How can I retrieve all links using XPath in Puppeteer when there are issues with pausing or functionality?

I am having issues with using XPaths to select all links on a page in my Puppeteer app. Sometimes the method I am using gets stuck and causes my crawler to pause. I'm wondering if there is a better way to retrieve all links from an XPath or if there m ...

Ways to align DataGrid columns to begin from the right in Material UI

In my project, I am using a data-grid of Material UI and I am looking to adjust the style so that all columns align from right to left. Each column should start on the right side. You can view the code on this sandbox. ...

How can I use jQuery to locate all elements that match a specific style within the DOM?

Similar Question: How can I target hidden elements? Selecting multiple elements with CSS display:none property <div class="container"> <p style="display:none">I am hidden</p> <p>I am visible</p> <p>I am also ...

Creating a method for a Discord Bot to communicate through a Webhook (loop)

I am looking to enhance my bot's functionality by implementing a webhook triggered by a specific command. Once activated, the webhook should send a message at regular intervals. The idea is to obtain the token and ID of the created webhook, and then ...

Difficulty redirecting Ajax call to a timed-out, CAS-protected server

Our website's login system utilizes CAS for single sign-on. The CAS server is operating the JASIG CAS server at , while our web server runs on Rails at . Due to security reasons, the Rails server has a relatively short session timeout, resulting in o ...

How can I retrieve the attributes of multiple identical components within a webpage?

I've recently delved into learning Vue and decided to create a small application for adding fractions together. I have developed two main components: Fraction.vue and App.vue. The App.vue component contains multiple instances of the Fraction component ...