ItzCrazyKns / Perplexica

Perplexica is an AI-powered search engine. It is an Open source alternative to Perplexity AI
MIT License
16.74k stars 1.57k forks source link

IPs and ports hardcoded in frontend javascript scripts (docker, pulled from hub) #403

Closed daniel-l closed 1 month ago

daniel-l commented 1 month ago

Describe the bug Perplexica's frontend usees hardcoded IPs and ports in it's javascripts. When deploying Perplexica on a remote server (e.g. a headless machine on the LAN and not on the user's PC) the frontend won't work. The spinning icon will be displayed endlessly and the dev console will still try to connect to a non-existing Perplexica backend on the local machine.

To Reproduce Steps to reproduce the behavior:

  1. Follow docker installation instructions on github
  2. Modify config.toml and docker-compose.yaml (e.g. setting "localhost" to actual host IP, changing ports to unused ports on host machine)
  3. Start docker image
  4. Open Perplexica web interface on host machine

    • interface loads but displays an endlessly spinner icon
    • dev console shows errors: a javascript still tries to access the hardcoded IP:port combination 127.0.0.1:3001 to connect to the backend API:

      Failed to load resource: the server responded with a status of 404 (Not Found)
      127.0.0.1:3001/api/models:1 
      
      Failed to load resource: net::ERR_CONNECTION_REFUSED
      453-761486cdb5440475.js:1 
      
      Uncaught (in promise) TypeError: Failed to fetch
      at 453-761486cdb5440475.js:1:31048
      at 453-761486cdb5440475.js:1:33120
      at aI (fd9d1056-7f47edce5fc91f7c.js:1:72882)
      at a3 (fd9d1056-7f47edce5fc91f7c.js:1:84323)
      at e (fd9d1056-7f47edce5fc91f7c.js:1:85465)
      at a5 (fd9d1056-7f47edce5fc91f7c.js:1:85777)
      at a8 (fd9d1056-7f47edce5fc91f7c.js:1:84845)
      at a5 (fd9d1056-7f47edce5fc91f7c.js:1:85906)
      at a8 (fd9d1056-7f47edce5fc91f7c.js:1:84845)
      at a5 (fd9d1056-7f47edce5fc91f7c.js:1:85906)
    • as the script is executed on the user's local machine/browser and there's no Perplexica backend running on it, accessing the API fails.

Expected behavior Perplexica should fully respect a user's IP and port modifications in config.toml an docker-compose.yaml to ensure that remote deployments and changed ports (e.g. because the default ports are already in use) are used app wide.

ItzCrazyKns commented 1 month ago

You can use docker compose up -d --build to build your own images, I can't be building images for everyone's IP nor it is possible to change the NextJS env vars at runtime, there's nothing I can do.

daniel-l commented 1 month ago

there's nothing I can do.

See https://publication.hikmahtechnologies.com/dynamically-passing-ip-at-runtime-in-a-dockerized-react-app-1b892442fba0

It's easily done at runtime and there's no need to provide separate images for every possible IP:port combination.

ItzCrazyKns commented 1 month ago

That's a really bad way of changing variables. It might mess with other parts of the application and introduce unexpected behavior. The current method of building custom images is more reliable for preventing potential issues.