0

For reference this repo contains a sample code (clone, install npm run server).

This is my server.js

const express = require('express');

const app = express();

app.get('/', (req, res) => res.send('Hello World!'));
app.post('/', (req, res) => res.send('Got a POST request'));
app.put('/', (req, res) => res.send('Got a PUT request at /'));
app.delete('/', (req, res) => res.send('Got a DELETE request at /user'));

const PORT = process.env.PORT || 5000;

app.listen(PORT, () => console.log(`Listening on ${PORT}`));

When I run locally npm run server and test with Postman I get the correct strings when calling the respective method (GET / => 'Hello World!', POST / => 'Got a POST request', and so on.

Then I have a Ubuntu droplet in DigitalOcean that I:

  • Created a user
  • apt-get update and dit-upgrade
  • Installed node v12.16.1 with npm 6.13.4 and git
  • Then git clone git@github.com:Kmelow/route-bug.git (this is repo where my code is)
  • cd, npm install and npm start

Next, I used Postman to test using the new URL.

Then, if I do a GET, POST, PUT, DELETE or any other method I always get Hello World!.

I can't understand why. What I'm doing wrong?

Kmelow
  • 203
  • 1
  • 3
  • 12
  • I can think of no other possible cause besides a mis-configured nginx proxy in front of your server. – jfriend00 Mar 22 '20 at 03:26
  • Some possibilities: [Nginx https rewrite turns POST to GET](https://serverfault.com/questions/434205/nginx-https-rewrite-turns-post-to-get) and [POST Request redirects to GET in Nginx proxy and NodeJS](https://www.digitalocean.com/community/questions/post-request-redirects-to-get-in-nginx-proxy-and-nodejs) and [Post request turns into Get request](https://stackoverflow.com/questions/24028719/post-request-turns-into-get-request). – jfriend00 Mar 22 '20 at 03:31

0 Answers0