Don't know how to use CORS_URL when hosting an instance #360

Closed
opened 2025-11-09 09:47:18 -06:00 by GiteaMirror · 8 comments
Owner

Originally created by @owendswang on GitHub (Jul 20, 2024).

bug description

I'm using docker compose to setup self-hosted service. But the cors restriction blocks me from accessing api url even when CORS_URL is set.

reproduction steps

  1. add CORS_URL to docker-compose.yml.
  2. 'docker compose up -d'
  3. download any url.
  4. error in console: 'Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://192.168.1.6:9000/api/json. (Reason: CORS request did not succeed). Status code: (null)'

screenshots

null

any url

platform information

  • OS: ubuntu server 64bit arm64
  • browser: firefox
  • version: 7 (7.14.6)

additional context

My 'docker-compose.yml' file content:

services:
    cobalt-api:
        image: ghcr.io/imputnet/cobalt:7
        restart: unless-stopped
        container_name: cobalt-api

        init: true

        # if container doesn't run detached on your machine, uncomment the next line
        #tty: true

        ports:
            - 9000:9000/tcp
            # if you're using a reverse proxy, uncomment the next line and remove the one above (9000:9000/tcp):
            #- 127.0.0.1:9000:9000

        environment:
            # replace https://api.cobalt.tools/ with your instance's target url in same format
            API_URL: "http://192.168.1.6:9000/"
            # replace eu-nl with your instance's distinctive name
            API_NAME: "zh-cn"
            # if you want to use cookies when fetching data from services, uncomment the next line and the lines under volume
            COOKIE_PATH: "/cookies.json"
            # see docs/run-an-instance.md for more information
            CORS_URL: "http://192.168.1.6:9001/"
        labels:
            - com.centurylinklabs.watchtower.scope=cobalt

        # if you want to use cookies when fetching data from services, uncomment volumes and next line
        volumes:
            - ./cookies.json:/cookies.json

    cobalt-web:
        image: ghcr.io/imputnet/cobalt:7
        restart: unless-stopped
        container_name: cobalt-web

        init: true

        # if container doesn't run detached on your machine, uncomment the next line
        #tty: true

        ports:
            - 9001:9001/tcp
            # if you're using a reverse proxy, uncomment the next line and remove the one above (9001:9001/tcp):
            #- 127.0.0.1:9001:9001

        environment:
            # replace https://cobalt.tools/ with your instance's target url in same format
            WEB_URL: "http://192.168.1.6:9001/"
            # replace https://api.cobalt.tools/ with preferred api instance url
        labels:
            - com.centurylinklabs.watchtower.scope=cobalt

    # update the cobalt image automatically with watchtower
    watchtower:
        image: ghcr.io/containrrr/watchtower
        restart: unless-stopped
        command: --cleanup --scope cobalt --interval 900 --include-restarting
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
Originally created by @owendswang on GitHub (Jul 20, 2024). ### bug description I'm using docker compose to setup self-hosted service. But the cors restriction blocks me from accessing api url even when CORS_URL is set. ### reproduction steps 1. add CORS_URL to docker-compose.yml. 2. 'docker compose up -d' 3. download any url. 4. error in console: 'Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://192.168.1.6:9000/api/json. (Reason: CORS request did not succeed). Status code: (null)' ### screenshots null ### links any url ### platform information - OS: ubuntu server 64bit arm64 - browser: firefox - version: 7 (7.14.6) ### additional context My 'docker-compose.yml' file content: ``` services: cobalt-api: image: ghcr.io/imputnet/cobalt:7 restart: unless-stopped container_name: cobalt-api init: true # if container doesn't run detached on your machine, uncomment the next line #tty: true ports: - 9000:9000/tcp # if you're using a reverse proxy, uncomment the next line and remove the one above (9000:9000/tcp): #- 127.0.0.1:9000:9000 environment: # replace https://api.cobalt.tools/ with your instance's target url in same format API_URL: "http://192.168.1.6:9000/" # replace eu-nl with your instance's distinctive name API_NAME: "zh-cn" # if you want to use cookies when fetching data from services, uncomment the next line and the lines under volume COOKIE_PATH: "/cookies.json" # see docs/run-an-instance.md for more information CORS_URL: "http://192.168.1.6:9001/" labels: - com.centurylinklabs.watchtower.scope=cobalt # if you want to use cookies when fetching data from services, uncomment volumes and next line volumes: - ./cookies.json:/cookies.json cobalt-web: image: ghcr.io/imputnet/cobalt:7 restart: unless-stopped container_name: cobalt-web init: true # if container doesn't run detached on your machine, uncomment the next line #tty: true ports: - 9001:9001/tcp # if you're using a reverse proxy, uncomment the next line and remove the one above (9001:9001/tcp): #- 127.0.0.1:9001:9001 environment: # replace https://cobalt.tools/ with your instance's target url in same format WEB_URL: "http://192.168.1.6:9001/" # replace https://api.cobalt.tools/ with preferred api instance url labels: - com.centurylinklabs.watchtower.scope=cobalt # update the cobalt image automatically with watchtower watchtower: image: ghcr.io/containrrr/watchtower restart: unless-stopped command: --cleanup --scope cobalt --interval 900 --include-restarting volumes: - /var/run/docker.sock:/var/run/docker.sock ```
GiteaMirror added the instance hosting help label 2025-11-09 09:47:18 -06:00
Author
Owner

@wukko commented on GitHub (Jul 20, 2024):

removing the trailing slash at the end of CORS_URL should solve the issue. for your config, it would look like this: http://192.168.1.6:9001

lmk if this helps and if it does, close the issue as completed!

@wukko commented on GitHub (Jul 20, 2024): removing the trailing slash at the end of CORS_URL should solve the issue. for your config, it would look like this: `http://192.168.1.6:9001` lmk if this helps and if it does, close the issue as completed!
Author
Owner

@owendswang commented on GitHub (Jul 22, 2024):

@wukko Thanks. But it does not work. The error remains.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://192.168.1.6:9000/api/json. (Reason: CORS request did not succeed). Status code: (null).
@owendswang commented on GitHub (Jul 22, 2024): @wukko Thanks. But it does not work. The error remains. ``` Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://192.168.1.6:9000/api/json. (Reason: CORS request did not succeed). Status code: (null). ```
Author
Owner

@wukko commented on GitHub (Jul 22, 2024):

is it http or https? make sure the protocol matches

@wukko commented on GitHub (Jul 22, 2024): is it http or https? make sure the protocol matches
Author
Owner

@wukko commented on GitHub (Jul 22, 2024):

can you take a screenshot of your entire browser window with cobalt frontend url, network dev tools tab, and related request visible?

@wukko commented on GitHub (Jul 22, 2024): can you take a screenshot of your entire browser window with cobalt frontend url, network dev tools tab, and related request visible?
Author
Owner

@owendswang commented on GitHub (Jul 22, 2024):

image
@wukko FYI.

@owendswang commented on GitHub (Jul 22, 2024): ![image](https://github.com/user-attachments/assets/efe5d1f2-434a-41d9-a10e-3728bc999119) @wukko FYI.
Author
Owner

@ihatespawn commented on GitHub (Jul 22, 2024):

is your api at http://192.168.1.6:9000/ or https://192.168.1.6:9000/ ?

if at http://192.168.1.6:9000/, your docker-compose.yml file is set up wrong

@ihatespawn commented on GitHub (Jul 22, 2024): is your api at http://192.168.1.6:9000/ or https://192.168.1.6:9000/ ? if at http://192.168.1.6:9000/, your `docker-compose.yml` file is set up wrong
Author
Owner

@owendswang commented on GitHub (Jul 22, 2024):

@ihatespawn It's 'http'. In 'docker-compose.yml' file, it's 'http://192.168.1.6:9000/' too. Why it's requesting 'https'?
.... Oh, I guess it's because I forgot to set API_URL for cobalt-web instance.
Thanks guys!

@owendswang commented on GitHub (Jul 22, 2024): @ihatespawn It's 'http'. In 'docker-compose.yml' file, it's 'http://192.168.1.6:9000/' too. Why it's requesting 'https'? .... Oh, I guess it's because I forgot to set API_URL for cobalt-web instance. Thanks guys!
Author
Owner

@owendswang commented on GitHub (Jul 22, 2024):

Thanks guys.

@owendswang commented on GitHub (Jul 22, 2024): Thanks guys.
Sign in to join this conversation.