Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

339
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda