Reputation: 133
I have a digital ocean droplet that is running a nodeJS server being run with pm2. When I run my preact app locally with the io.connect set to
io.connect('app.ardilabs.com:9080');
app.ardilabs.com is where the nodeJS server lives.
The locally run web app will connect to the remote server from D.O. and then will update my app with the data I am POSTing using Postman.
When I try to build the app and put it on the same D.O droplet and serve the app using nginx the app will load when you go to the URL but it won't connect to the nodeJS server. When I try to POST something I get a confirmation from the server that it got my data but it's never forwarded to the app.
Why does it work locally and with a remote server but not when I am hosting the app and serving it with nginx? I am really stumped.
Here is the relevant server code:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
// routes will go here
io.on('connection', function(socket){
//We need a connection but we don't need to do anything about it
});
// start the server
http.listen(9080, function() {
console.log('listening on *:9080');
});
Here is the relevant client code:
import io from 'socket.io-client';
const socket = io.connect('app.ardilabs.com:9080');
A few extra notes:
If I am missing any info needed please let me know!
Upvotes: 1
Views: 345
Reputation: 133
I figured out what the issue was.
Once I put a cert on my nginx server I didn't realize that I needed to configure my express server to also use HTTPS. Once I enabled HTTPS on the express server the data went through to the connected web app just fine.
Upvotes: 1