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

149
Visualizações
Axios Post request to Express backend gives 404

I have a simple blog site using EJS, Express, and Axios. No frontend framework - plain JS and EJS. I'm still relatively new to Express and Axios. Trying to do a simple POST request with Axios to the router file router.post("/admin/posts/create-post", adminCreatePost) and get a POST http://localhost:3000/admin/posts/create-post 404 (Not Found) error in the browser console.

The adminCreatePost function is from a separate controller file. I commented out all code and put a simple console.log("hello from the controller") in the controller and it does log the message, but still get the 404 error in the browser console. So the adminCreatePost required in doesn't seem to be the issue.

I've triple checked the url I pass in to Axios POST call. I tried a simple GET request with Axios to make sure Axios itself wasn't the problem - the GET request worked.

I'm sure it's probably something simple/silly I'm not thinking about or overlooking. Any thoughts?

If you need more info, happy to answer.

savePost.js on the frontend

    document.getElementById('save-post-button').addEventListener('click', (event) => {
        event.preventDefault();

        let postContent = [];
        let textAreas = document.getElementsByTagName('textarea');
        const arrayOfTextAreas = Array.prototype.slice.call(textAreas);
        arrayOfTextAreas.forEach(element => {
            const block = new Object();
            block.type = element.dataset.blockType;
            block.contents = element.value;
            console.log(block);
            postContent.push(block);
        })

        let newPost = {
            postReadyToView: Boolean(document.getElementById('new--ready-for-viewers').value),
            postPath: document.getElementById('new--post-path').value,
            postTitle: document.getElementById('new--post-title').value,
            postDate: document.getElementById('new--email-subscribers-date').value,
            postUpdateDate: null,
            postContent: postContent
        };

        axios.post("/admin/posts/create-post", newPost)
            .then(res => console.log(res))
            .catch(error => console.log(error))
    })

router.js on backend

const {postREQ_adminCreatePost } = require("./controllers/controllerAdmin");

router.post("/admin/posts/create-post", postREQ_adminCreatePost)

module.exports = router;

controllerAdmin.js on backend

exports.postREQ_adminCreatePost = (req, res, next) => {
  console.log('hello from controller');
  next();
}
about 4 years ago · Juan Pablo Isaza
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