Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

353
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda