Ad

404 - From Nginx Application To Remote Servers Localhost?

I am new to react, and wanted to deploy a site to my domain with Nginx. I need to make the application to be able to fetch from client side, to the localhost of the remote server hosting the site with Nginx. I know exposing this many details might make security experts and hackers either drool or shake their heads. But I am losing my sanity from this.

This is a filtered version of my Node.js express service running on the remote server:

const express = require("express")
const cors = require("cors")
const app = express();
const PORT = 1234;
const spawn = require("child_process").spawn;

app.use(cors())

app.listen(PORT,  function(){
console.log(`listening on port:${PORT}...`)
})

app.get("/api/play/:choice", function(req,res){
    pythonProcess = spawn('python',["./script.py", req.params.choice]);
    pythonProcess.stdout.on('data', function(data) {
    res.status(200).send(data.toString('utf-8'))})
})

this is how I am fetching from the deployed react application. The public IP of the droplet I am using

fetch(`104.248.28.88/1234/api/play/rock`)
Ad

Answer

Change the fetch to replace the / with a : to indicate port, rather than directory

fetch("104.248.28.88:1234/api/play/rock")
Ad
source: stackoverflow.com
Ad