Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

340
Views
Can't reach server, React 404 error 'Post'

I can't reach server side I checked everything it should work error is: "POST http://localhost:3000/ 404 (Not Found)"

Here is my code

On client side here, I call createPost at jsx file and in actions/post.js file:

import * as api from "../api/index";  
import * as types from "./types";

export const createPost = (post) => async (dispatch) =>{
    try {
        const {data} = await api.createPost(post);
        dispatch({
            type: types.CREATE_POST,
            payload: data,
        });

    } catch (error) {
        console.log(error);
    }
};

from here it should call the api,

import axios from "axios";
const apiEndpoint = "/";

export const fetchPosts = async () => await axios.get(apiEndpoint);
export const createPost = async (post) => await axios.post(apiEndpoint, post);

and from there to server side but there is a error at createPost first.

btw in server,

import express from "express";
import {getPosts, createPost} from "../contollers/posts.js";


const router = express.Router();

//localhost/posts
// GET POST DELETE UPDATE

router.get("/", getPosts);
router.post("/", createPost);

export default router;

and in controller:

export const createPost = async(req,res) => {
const post = req.body;
const newPost = new Post(req.body);
try{
    await newPost.save();
    res.status(201).json(newPost);
}catch(error){
    res.status(409).json({
        message: error.message,
    });
}    

};

thanks for help

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

yeah its my stupidity that correcting some router&dom versions and url to 5000(which is the server) solved the issue

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!