Why Am I Still Getting a 431 (Request Header Fields Too Large) Error in My React App Despite Clearing

Whenever I try to run a post request in my React app, I encounter the "431 (Request Header Fields Too Large)" error and I'm unable to identify the cause. Is there anyone who can assist me with this problem?

I've attempted various solutions based on responses to similar inquiries:

  • Clearing cache and cookies
  • Upgrading from node version v12.19.0 to v14.17.2
  • Specifying header specifications in the request

The function responsible for submitting the POST request:

handleSubmit(evt){
    axios.post('/creator/new', {
        username: this.state.username,
        password: this.state.password,
        profilePic: this.state.profilePic,
        firstName: this.state.firstName,
        lastName: this.state.lastName,
        dob: this.state.dob,
        country: this.state.country
    }, {headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json; charset=UTF-8'
    }}).then(response => {
        console.log('response received');
    })
    evt.target.reset();
    this.props.history.push(`/creator/${this.state.username}`);
    this.props.addCreator(this.state);
}

Server details:

const express = require('express');
const cors = require('cors');

const creatorsRoutes = require('./routes/creators-routes');
const ipsumsRoutes = require('./routes/ipsums-routes');


const app = express();

app.use(cors());
app.use(express.json());

app.use((req, res, next) => {
  console.log('request received')
  res.send(req.path);
  console.log('request body sent back')
})

app.use('/creator', creatorsRoutes); 


const mongoose = require('mongoose');
mongoose.connect("mongodb+srv://SkyeWulff:************retryWrites=true&w=majority", {useNewUrlParser: true, useUnifiedTopology: true})
    .then(() => {
      console.log('Connection open');
    })
    .catch(err => {
      console.log('Error occured:');
      console.log(err);
    })
let db = mongoose.connection;

db.on('error', console.error.bind(console, 'Connection Error'));

db.once('open', function(){console.log("successfully connected to MongoDB")});

app.listen(5000, () => {
  console.log("listening on port 5000");
})

Router used by the server:

const express = require('express');
const creatorsController = require('../controllers/creators-controllers');

const router = express.Router();


router.get('/creator/id', creatorsController.getCreator);


router.post('/new', creatorsController.addCreator);

module.exports = router;

Controller employed by the router:

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const creatorSchema = new Schema({
    username: String,
    password: String,
    profilePic: String,
    firstName: String,
    lastName: String,
    dob: Date,
    country: String
});
module.exports = mongoose.model('Creator', creatorSchema);

Filetree Structure: Filetree

Answer №1

In reference to an explanation provided at this Stack Overflow post

(the maximum HTTP header size can be adjusted):
By executing the command "node --max-http-header-size 16000 client.js"

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

Please provide the link to your ReactJS app that is hosted on Azure's static web app, or simply refresh the

I currently have a ReactJS application hosted on Azure StaticWebApp that interacts with API endpoints for backend functionality. I am looking to share specific URLs, similar to how we include them in emails, so users can easily access pages like https://w ...

Enhancing my code by implementing various conditions in React

Looking for ways to enhance my code quality (Very Important, Important, Medium, Low, Good, Excellent,...) : { Header: "Opinion", accessor: (row) => row.opinion, Cell: props => <span> {props.value == ...

Shattering the barrier

When using the bubble chart, I encountered an issue with adding line breaks in text. No matter what I tried, such as using \n or , it consistently showed me an error. import React from 'react'; import { BubbleChart,key,data } from 're ...

Optimal method for a React and HTML Select-component to output String values instead of Integer values

Within my React-class (JSX), I've included the following code: var Select = React.createClass({ onChange: function (ev) { console.log(ev.target.value); }, render: function() { var optionsHtml = this.state.options.map(function (el) { ...

Issues with loading NextJS videos can occur when accessing a page through a link, as the videos may fail to load without

Issue Greetings. The problem arises when attempting to load muse.ai videos on-page, specifically when accessing the page with a video embedded through a NextJS link. To showcase this issue, I have provided a minimal reproducible example on StackBlitz her ...

Transferring cookies across subdomains

I am facing an issue with an ajax request going from one subdomain to another, for example from sub1.example.com to sub2.example.com. Despite having a cookie set for all domains (cookie domain='.example.com'), the cookie is not being sent to the ...

Flex column MUI Data Grid with minimum width to fit content

I am currently working with the MUI Data Grid under an MIT license. My columns are configured as flexible to make use of the available width. However, I want the table to have overflow capabilities for instances where it's resized too small. For ins ...

Transforming an uncontrolled Autocomplete component into a controlled one

Why am I receiving the error message "A component is changing an uncontrolled Autocomplete to be controlled. Elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled Autocomplete element ...

As I work on developing a React application, I encounter the following error or errors

Upon running create-react-app, I encountered an error message despite trying various solutions such as uninstalling the global package. The error persists with each attempt. The version of `create-react-app` you are currently using is 4.0.0, which is outda ...

Ensure that the bundled package for ReactJS only contains the necessary imports that are being utilized

Is it possible to use just a single component from the Material Ui library? I understand that I can import only one component using ES6 import, but does webpack treeshake and discard the other components from the library or include them in production? I w ...

The custom layout in NestJS version 13 failed to display

I have implemented NextJs 13 in my project for building purposes. I am trying to use CustomLayout as the primary layout for my entire website. Even though there are no errors, I am facing an issue where the CustomLayout does not display as expected. ...

Passing an ID in Next.js without showing it in the URL

I am looking to transfer the product id from the category page to the product page without showing it in the URL Category.js <h2> <Link href={{ pathname: `/product/car/${title}`, query: { id: Item.id, }, }} as={`/p ...

Issue with ReactTS Route Triggering Invalid Hook Call

My implementation of the PrivateRoute component is as follows: interface Props { path: string, exact: boolean, component: React.FC<any>; } const PrivateRoute: React.FC<Props> = ({ component, path, exact }) => { return ( ...

What could be causing the image not to appear on the React app?

I'm currently working on a react website, and I'm facing an issue with the image display on the single product page. Despite trying to tweak both the react and CSS code, I haven't been able to resolve the problem. Below is my react file: im ...

What is the best way to maintain the current position in a component while interacting with another component?

I have a component that displays a collection of cards with images. There is a button that toggles between showing another component and returning to the original list of cards. The issue I am encountering is that every time I return to the list of cards, ...

The term "Movie" is not compatible as a JSX component

Currently working on a movie app project but encountering issues with handling arguments and displaying them properly using TypeScript. The challenge lies in trying to map the movie object, display them individually on the homepage, and showcase all the re ...

Next.js does not recognize the definition of RTCPeerConnection

Looking for a way to utilize the React context API in order to pass an instance of RTCPeerConnection to my React Component tree. Despite being familiar with Next.js SSR feature, which initially renders components on the server side, none of the solutions I ...

Guide to deploying a Next JS App with Mongoose for MongoDB connectivity on Vercel

I am experiencing issues when trying to deploy my Next.js app on Vercel with a MongoDB connection. I have added environment variables on the Vercel site where we deploy the Next.js app. Is there anything wrong in the following file? next.config.js module. ...

There was a problem with the WebSocket handshake: the response header value for 'Sec-WebSocket-Protocol' did not match any of the values sent

I've encountered an issue with my React project that involves streaming live video through a WebSocket. Whenever the camera firmware is updated, I face an error in establishing the WebSocket connection. Here's how I initiate the WebSocket: wsRe ...

The styled component is not reflecting the specified theme

I have a suspicion that the CSS transition from my Theme is not being applied to a styled component wrapped in another function, but I can't pinpoint the exact reason. I obtained the Basic MUI Dashboard theme from this source and here. Initially, inte ...