octachrome / treason

A clone of the card game Coup written in Node.js
Other
137 stars 79 forks source link

[SOLVED] Starting my own server #31

Closed frothedoatmilk closed 4 years ago

frothedoatmilk commented 4 years ago

Now, I'm well aware that a server running this game already exists, however, that server resets and lags quite a bit, and I have a machine with a set URL that I want to create a treason server on. I have a functioning pouchDB / couchDB server running on it, but the treason server tries to create a game at 127.0.0.1 instead of at the fixed URL. How do I fix this?

Just for reference, when the server is running and you open it from a web browser, this is all it says:

{"express-pouchdb":"Welcome!","version":"4.2.0","pouchdb-adapters":["leveldb"],"vendor":{"name":"PouchDB authors","version":"4.2.0"},"uuid":"bdf78359-f536-476d-8620-7da710ba75cb"}

And trying node server.js gives me the ECONNREFUSED error

octachrome commented 4 years ago

The web response you pasted is from pouchdb. What port are you running pouchdb on? And what port are you running Treason on? Could be they are the same hence the error? Could you paste the full output from node server.js in case that helps?

frothedoatmilk commented 4 years ago

Output from node server.js

(node:9369) UnhandledPromiseRejectionWarning: Error: not initialized
    at Object.<anonymous> (/home/brie/Documents/treason/dataaccess-couch.js:50:28)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/brie/Documents/treason/server.js:15:18)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
(node:9369) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:9369) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Failed to initialise database(s)
Error: connect ECONNREFUSED 127.0.0.1:5984
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1134:16) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 5984
}

I know that pouchDB is hosting on port 5984 because I can access the utils page at domain:594/_utils

Everything apparently works fine when I host the pouchDB server at 127.0.0.1, but I don't have access to that website, I'm running everything through an SSH session right now.

octachrome commented 4 years ago

I'm guessing that's a typo with the port number? Maybe pouch is not bound to localhost. Does http://127.0.0.1:5984 work in your browser? If not, reconfigure pouch ip address or edit dataaccess-couch.js and pass your ip address to the cradle.Connection function. Don't know the syntax, sorry I'm on my phone.

frothedoatmilk commented 4 years ago

Okay, progress! Now node server.js doesn't crash immediately, I changed the code from new cradle.Connection(); to

var connection = new(cradle.Connection)({
        host: '[the domain name]'
});

However, when opening the page in a browser, I still see that readout from pouch. There are these other errors, I'm uncertain if they are related:

(node:9688) UnhandledPromiseRejectionWarning: Error: not initialized
    at Object.<anonymous> (/home/brie/Documents/treason/dataaccess-couch.js:52:28)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/brie/Documents/treason/server.js:15:18)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
(node:9688) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:9688) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
octachrome commented 4 years ago

Treason runs on http://localhost:8080 by default, try that. You can also pass a port to server.js, (e.g. 80, if you want the server to run on http://localhost), but I forgot the syntax.

frothedoatmilk commented 4 years ago

I understand that it runs by default at localhost:8080, I'm trying to get it to run on the domain name, so I can access it from outside that computer and its local network.

octachrome commented 4 years ago

What url are you trying to access the game on? Are you accessing the site from the host machine or a different machine? Is there a firewall? How you have set up the domain name? Please provide as much info as possible.

frothedoatmilk commented 4 years ago

I am using a university machine that has a static IP and URL. I have used this same machine for numerous other purposes, such as an FTP server and an SSH server, like how I am using it now. Presumably the issue here is that the university firewall is blocking the port 8080, but that seems unlikely, considering something like port 5984 is open. I need to figure out how to tell treason's server.js to direct its attention to the url or static IP, rather than 127.0.0.1 or localhost.

octachrome commented 4 years ago

You could try adding the ip to the call to app.listen(argv.port) in server.js. Can you answer my other questions? Particularly the url.

frothedoatmilk commented 4 years ago

Okay, progress? Now instead of 127.0.0.1, its using the IP of the URL, firenze.nmsu.edu. However, now server.js won't connect to pouchDB, even though they are both directed at firenze.nmsu.edu. I tried directing pouchDB to the IP instead of URL, same issue. Here is the exit log from node server.js:

(node:14935) UnhandledPromiseRejectionWarning: Error: not initialized
    at Object.<anonymous> (/home/brie/Documents/treason/dataaccess-couch.js:52:28)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/brie/Documents/treason/server.js:15:18)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
(node:14935) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14935) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Failed to initialise database(s)
Error: connect ECONNREFUSED 128.123.181.114:5984
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1134:16) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '128.123.181.114',
  port: 5984
}

Just for note, I didn't want to expose the URL because if for some benign reason an NMSU IT dude is also trying to do this, they'll either take the computer or revoke it's static IP and domain name, which would be mighty unfortunate.

frothedoatmilk commented 4 years ago

It would be cool if I understood how pouchDB and the server interact, I could try and troubleshoot from there. I'll leave the server running with no admin password on the pouchDB utils, if it does anything 😄

octachrome commented 4 years ago

It would be cool if I understood how pouchDB and the server interact

It's pretty simple really: pouchDB runs a web server on port 5984, and server.js connects to the pouchDB web server and also runs its own web server on port 8080. I don't see why server.js cannot connect to 128.123.181.114:5984 when I can connect that address from my laptop and you can connect to it from your browser.

Assuming that pouchDB is running on firenze, and assuming that you are trying to run node server.js on firenze too, can you try connecting to pouch with curl from an SSH session on firenze? I.e., curl http://128.123.181.114:5984 or curl http://127.0.0.1:5984

frothedoatmilk commented 4 years ago

okay so i'm

octachrome commented 4 years ago

You can pass port 80 to node server.js. But if you're running on Linux you'll probably need to run node as root otherwise it will not be allowed to bind to ports <1024. If that's not possible you could do what you suggested and use an apache redirect.

frothedoatmilk commented 4 years ago

I can do sudo no problemo. Thanks for all the help mate! You ought to change the docs to explain how to do this because, no offense, the version that is hosted at thebrown.net resets super frequently.