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

190
Visualizações
POST http://127.0.0.1:5500/add 405 (Method Not Allowed)

Could you help me solve this error? It seems that I can not connect between server.js and app.js.

What I want to do is: display the result of the postData('/add', {answer:42}); and postData('/addMovie', {movie:'the matrix', score:5}); in the console.

Thank you for your help in advance.

error image

server.js

// Setup empty JS object to act as endpoint for all routes
projectData = {};

// Require Express to run server and routes
const express = require('express');//add

// Start up an instance of app
const app = express();//add

/* Dependencies */
const bodyParser = require('body-parser') //add
/* Middleware*/
//Here we are configuring express to use body-parser as middle-ware.
//we can connect the other packages we have installed on the command line to our app in our code with the .use() method
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// Cors for cross origin allowance
const cors = require('cors');//add
app.use(cors());//add

// Initialize the main project folder
app.use(express.static('website'));

////////////////////creating a local server
const port = 5500;//add
// Setup Server
//////////////////////add
const server = app.listen(port, listening);
function listening(){
    // console.log(server);
    console.log(`running on localhost: ${port}`);
};

app.get('/all', function (req, res) {
    res.send(projectData)
})

// POST route
const data = []
app.post('/add', callBack);

function callBack(req,res){
    res.send('POST received');
    console.log(data)
}

const movieData = []
app.post('/addMovie', addMovie )

function addMovie (req, res){
    movieData.push(req.body)
    console.log(movieData);
}

app.js app.js

[Addition] Thank you for your feedback!! I changed the port in server.js, but nothing changed. port5500

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The issue was resolved.

// when using local server ( ≒ server.js in this case)
postData('/add', {answer:42});
postData('/addMovie', {movie:'the matrix', score:5});

// when using live server
postData('http://localhost:5500/add', {answer:42});
postData('http://localhost:5500/addMovie', {movie:'the matrix', score:5});
about 4 years ago · Juan Pablo Isaza Relatório

0

You need to add an "allow" in the header field to support this or explicitly allow it in your webserver configuration

A lot of the time, this is set up in the configuration of your .htaccess or nginx.conf file (depending on the webserver). It will commonly be found in your RewriteRule section. You can look for a "R=405" flag there.

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