Source:  Twitter logo

Not sure what's going on with my code, but I'm trying to just do a test run with axios console logging something out, but I'm getting a 404.

class SubscribeForm extends Component {
  constructor(props) {
    this.state = {value: ''};

    this.emailChange = this.emailChange.bind(this);
    this.emailSubmit = this.emailSubmit.bind(this);

  emailChange(e) {

  emailSubmit(e) {
    e.preventDefault();'/subscribe', {
      email: '',
      headers: {
        'Content-Type': 'application/json;charset=UTF-8',
        "Access-Control-Allow-Origin": "*",
    }).then(res => {
      if( {
        this.setState({email: ''})
    }).catch(error => {
      if (error.response) {
        // The request was made and the server responded with a status code
        // that falls out of the range of 2xx
      } else if (error.request) {
        // The request was made but no response was received
        // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
        // http.ClientRequest in node.js
      } else {
        // Something happened in setting up the request that triggered an Error
        console.log('Error', error.message);

  render() {
    const { classes } = this.props;
    return (
      <div className={classes.subFormSection}>
        <p className={classes.formHelper}>
          Join the club, enter your email address

        <form method="post" className={classes.subFormWrap} onSubmit={this.emailSubmit}>
            value = {this.state.value}
            onChange = {this.emailChange}
            <Icon className={classes.rightIcon}>send</Icon>

I tried adding headers into axios to see if thats the issue, but i don't think it is (or perhaps I'm doing it wrong).

Also, I don't have a /subscribe file, I don't think I need one? Since, I'm capturing it with express here:

const cors = require("cors");

app.use(cors());"/subscribe", (req, res, next) => {

This file is within my server files, while the react portion is within client files. I have proxy set up, so when I have run the server, front end and back end is talking to each other.

Updated 404 status turned (pending)

I also have set up proxy middleware in my client folder setupProxy.js

const proxy = require("http-proxy-middleware");

module.exports = function(app) {
  app.use(proxy("/subscribe", {
    target: "http://localhost:5000"

I'm getting in the request header in my network request for /subscrib:

Provisional headers are shown

Is this causing it to be (pending)?

From what I can see, it seem your server and client app run on different ports. If that is the case you cannot do this:'/subscribe', {
      email: '',
      headers: {
        'Content-Type': 'application/json;charset=UTF-8',
        "Access-Control-Allow-Origin": "*",

You are using the path /subscribe without a host. Axios tries to use the host from which your client app is running and it doesn't find that path hence the 404 status code.

If this is the case, you can fix it by using the host and port of your server before the /subscribe path. See below:'localhost:4000/subscribe', {
      email: '',
      headers: {
        'Content-Type': 'application/json;charset=UTF-8',
        "Access-Control-Allow-Origin": "*",

Kindly change the port here localhost:4000 to your server port.

Note: This is for your local development only.

If you plan on deploying the app, you might want to use process.env.PORT instead.

2 users liked answer #0dislike answer #02
codejockie profile pic

You can use browser's inspect element to check if request is made properly(Inspect Element > Network).

By looking at code I think you are missing base url.

it should be like + port + request url)

0 users liked answer #1dislike answer #10
Sagar profile pic

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).