sungshon / PimpMyStremio

Local add-on manager for Stremio
MIT License
381 stars 51 forks source link

"Cannot GET /" error on headless server #87

Closed adocampo closed 4 years ago

adocampo commented 4 years ago

After testing successfully PMS on my PC, I want to let it running on my home server, which is 24/7 online, so I can access PMS on all my stremio devices like firestick or android seamlessly.

I copied the x86 binary to the server and ran it, with this output

./PimpMyStremio 
PimpMyStremio - Checking for updates
PimpMyStremio - New version found
PimpMyStremio - Downloading new version
(node:1233167) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/root/.local/share/PimpMyStremio/xdg-open'
    at Object.fs.openSync (fs.js:646:18)
    at Object.fs.openSync (pkg/prelude/bootstrap.js:490:32)
    at Object.fs.writeFileSync (fs.js:1299:33)
    at module.exports.url (/snapshot/PimpMyStremio-master/upd/openLinux.js:10:5)
    at module.exports.start.getPort.then.server.listen.opn.catch (/snapshot/PimpMyStremio-master/upd/api.js:28:7)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
(node:1233167) 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:1233167) [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.
PimpMyStremio - Finished downloading new version
PimpMyStremio - Unpacking new version
PimpMyStremio - Finished unpacking new version
PimpMyStremio - Updated to v1.2.3
PimpMyStremio - Successfully updated add-ons list from remote source
Remote access choice: No (local)
PimpMyStremio server running at: http://127.0.0.1:7777
PimpMyStremio - Could not find systray binary path, skipping

As I saw it was listening on 127.0.0.1:7777, I opened the file ./LocalData/assets/LocalData/PimpMyStremio-userConfig.json and let it like this:

{
  "installedAddons": [],
  "runningAddons": [],
  "userDefined": {
    "autoLaunch": {
      "title": "Run on start-up",
      "type": "boolean",
      "default": false,
      "value": false
    },
    "theme": {
      "title": "Theme",
      "type": "select",
      "options": [
        "Light",
        "Dark",
        "Rusty",
        "Sky",
        "Light Orange",
        "Light Blue",
        "Light Green",
        "Dark Purple",
        "Dark Blue",
        "Dark Green"
      ],
      "default": "Light",
      "value": "Light"
    },
    "serverPort": {
      "title": "Server port",
      "type": "number",
      "default": 7777,
      "value": 7777
    },
    "password": {
      "title": "Server Password",
      "type": "string",
      "default": "",
      "value": ""
    },
    "addonsListUrl": {
      "title": "Remote Add-ons List URL",
      "type": "string",
      "default": "https://raw.githubusercontent.com/sungshon/PimpMyStremio/master/src/addonsList.json",
      "value": "https://raw.githubusercontent.com/sungshon/PimpMyStremio/master/src/addonsList.json"
    },
    "externalUse": {
      "title": "Remote Access",
      "type": "select",
      "options": [
        "No (local)",
        "LAN",
        "External"
      ],
      "default": "No (local)",
      "value": "LAN"
    }
  }
}

Now, output shows this:

./PimpMyStremio 
PimpMyStremio - Checking for updates
PimpMyStremio - Already have latest version
PimpMyStremio - Successfully updated add-ons list from remote source
Remote access choice: LAN
Domain IP: 192.168.1.100
Domain: 192-168-1-100.519b6502d940.stremio.rocks
PimpMyStremio server running at: https://192-168-1-100.519b6502d940.stremio.rocks:7777
PimpMyStremio - Could not find systray binary path, skipping

And I can see now is listening on all the interfaces

$ ss -putan | grep 7777
tcp   LISTEN     0      511                         *:7777                        *:*     users:(("engine",pid=1301307,fd=11))

But when I try to access from my computer through https://192.168.1.100:7777 or the hostname generated, in my case https://192-168-1-100.519b6502d940.stremio.rocks:7777, I get the error Cannot GET / image

As my server is headless, I configured back to "No (local)" and tried CLI internet browser "links", and the same error appears Peek 2020-09-21 00-35

It's strange, as I tested it on my computer without problems in "LAN" mode image

Both computers have static IP, but I noticed Stremio files are placed in different places on my computer (~/.local/share/PimpMyStremio) and my server (on a directory called LocalData on the same place where PimpMyStremio binary is placed). Directory structure is also different.

Am I missing something?

sungshon commented 4 years ago

Are you running Docker on your server? There's a PR to add Docker support that was opened recently: https://github.com/sungshon/PimpMyStremio/pull/85

This might make things a bit simpler for you. I'm not sure yet, but the Docker image might break the auto-updater though.. (checked the Docker PR in the meanwhile, it shouldn't break the auto-updater)

The chosen app data dir on your server does seem strange, this directory is chosen based on the APPDATA process environment variable, which might be different on your server compared to your PC. (see: https://github.com/sungshon/PimpMyStremio/blob/master/src/lib/dirs/rootDir.js#L4 )

Based on your logs, I can tell that it expects this folder to exist: /root/.local/share/, and this is probably the APPDATA folder on that server. If it does not exist, could you create it and give write access to the folder for the user that runs PMS? Otherwise, you could try changing the APPDATA environment variable to something else before running the app..

After you fix the APPDATA issue, you should try deleting all user configs and PMS, then downloading + starting it again. (so it can update again and hopefully use the correct folder)

sungshon commented 4 years ago

Actually, considering this logic:

let rootDir = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Preferences' : process.env.HOME + '/.local/share')

It looks like process.env.APPDATA does not exist on your server, so it falls back to process.env.HOME + '/.local/share', so the HOME process environment variable in your case is /root/, leading to /root/.local/share, which probably does not exist. And this most probably caused all the issues you're having.

adocampo commented 4 years ago

Ok, I did some more tests, and they were... well, a bit weird. No, I wasn't using docker, and as you suggested, all the fuss came for the APPDATA environment variable, which was in blank. I just created the /root/.local/share directory and started PMS again, it upgraded, restarted and it worked as expected. :tada:

PS: I tried also @sleeyax's docker image, but it ended with an error when adding the add-on on stremio image Yet I see the json on that URI image

The fun fact is setting up stremio locally on the headless server failed with the same error at first, but then started to work after a while with no action by my side, just waited a couple of minutes.

I'm opening a new issue for the pms-docker and in the meanwhile I will use pms manually installed, but this is not ideal, as I have all my services dockerized.

sungshon commented 4 years ago

I tried also @sleeyax's docker image, but it ended with an error when adding the add-on on stremio

Looking at your print screen for the manifest URL, it looks like it's not using SSL. Stremio only loads addons from SSL enabled links, the only exception is local links (127.0.0.1 and localhost), that's why the LAN feature is so important, as it enables SSL.