SolidJSS
SolidJS5mo ago
82 replies
Jason.json

Docker nginx proxy with Solid Start

Hi I am kind of new to reverse proxy. I have 3 containers frontend, backend and nginx.


My nginx config
location / {
        proxy_pass http://frontend:[my_frontend_port];
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /api/ {
        proxy_pass http://backend:[my_api_port]/;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

I want to use it like this inside solid app:

  fetch("/api/endpoint")...


my proxy setup:


...
server: {
      proxy: {
        "/api": {
          target: "http://backend:[backend_port]/api",
          changeOrigin: true,
          rewrite: (path: string) => path.replace(/^\/api/, "/api"),
        },
      },
    },


Errors I get:
  GET http://localhost/api/time net::ERR_ABORTED 404 (Not Found)


It seems like it does not know about existance of those api routes.

This is how i use it :
const response = await fetch("/api/time", {
          method: "GET",
          headers: {
            "Content-Type": "application/json",
          },
        });


Can someone help me with it?

It works on the server side with ssr with (http://backend:[backend_port]/api/time) but does not work on the client side.
Was this page helpful?