Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a bit of help accessing this outside the network, CORS issue #293

Open
Japhys opened this issue Sep 24, 2024 · 4 comments
Open

Need a bit of help accessing this outside the network, CORS issue #293

Japhys opened this issue Sep 24, 2024 · 4 comments
Labels
investigating Bugs that are still being investigated whether they are valid

Comments

@Japhys
Copy link

Japhys commented Sep 24, 2024

First of all: I really enjoyed playing around with this. I got it all working and it's a lot of fun!

I wanted to show some people in my office this application. Usually I just use nginx proxy manager to open it up *with access rules) but this time it didn't work. Seems to be CORS according to my browser console. Not sure how to fix this though.

Running Docker, Weaviate and Ollama versions on Linux.

2024-09-23_08-00

@wtavares
Copy link

wtavares commented Oct 15, 2024

+1 here...

I tried to remove the check origin at the api.py. But the front keeps the CORS error. The API is working.

`# Allow requests only from the same origin

app.add_middleware(

CORSMiddleware,

allow_origins=["*"], # This will be restricted by the custom middleware

allow_credentials=True,

allow_methods=["*"],

allow_headers=["*"],

)

Custom middleware to check if the request is from the same origin

@app.middleware("http")
async def check_same_origin(request: Request, call_next):
# Allow public access to /api/health
# if request.url.path == "/api/health":
# return await call_next(request)
#
# origin = request.headers.get("origin")
# if origin == str(request.base_url).rstrip("/") or (
# origin
# and origin.startswith("http://localhost:")
# and request.base_url.hostname == "localhost"
# ):
# return await call_next(request)
# else:
# # Only apply restrictions to /api/ routes (except /api/health)
# if request.url.path.startswith("/api/"):
# return JSONResponse(
# status_code=403,
# content={
# "error": "Not allowed",
# "details": {
# "request_origin": origin,
# "expected_origin": str(request.base_url),
# "request_method": request.method,
# "request_url": str(request.url),
# "request_headers": dict(request.headers),
# "expected_header": "Origin header matching the server's base URL or localhost",
# },
# },
# )

    # Allow non-API routes to pass through
    return await call_next(request)`

@thomashacker thomashacker added the investigating Bugs that are still being investigated whether they are valid label Dec 9, 2024
@thomashacker
Copy link
Collaborator

Hey everyone! Sorry for the late reply 🙏
Could you share a more information about your setup with nginx

@Japhys
Copy link
Author

Japhys commented Dec 30, 2024

@thomashacker

I only say this now :)

I am using this docker compose file

version: '3.8'

services:
  verba:
    image: semitechnologies/verba
    ports:
      - 8111:8000
    environment:
      - WEAVIATE_URL_VERBA=http://weaviate:8080
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - COHERE_API_KEY=${COHERE_API_KEY}
    volumes:
      - /srv/verba/data:/data/
    depends_on:
      weaviate:
        condition: service_healthy
    healthcheck:
      test: wget --no-verbose --tries=3 --spider http://localhost:8111 || exit 1
      interval: 5s
      timeout: 10s
      retries: 5
      start_period: 10s
    networks:
      - proxy

  weaviate:
    command:
      - --host
      - 0.0.0.0
      - --port
      - '8080'
      - --scheme
      - http
    image: semitechnologies/weaviate:1.25.10
    ports:
      - 8080:8080
      - 3000:8080
    volumes:
      - /srv/verba/weaviate/weaviate_data:/var/lib/weaviate
    restart: on-failure:0
    healthcheck:
      test: wget --no-verbose --tries=3 --spider http://localhost:8080/v1/.well-known/ready || exit 1
      interval: 5s
      timeout: 10s
      retries: 5
      start_period: 10s
    networks:
      - proxy
    environment:
      OPENAI_APIKEY: ${OPENAI_API_KEY}
      COHERE_APIKEY: ${COHERE_API_KEY}
      QUERY_DEFAULTS_LIMIT: 25
      AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
      PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
      ENABLE_MODULES: 'e'
      CLUSTER_HOSTNAME: 'node1'

networks:
  proxy:
    external: true

volumes:
  weaviate_data: {}

Using Nginx proxy manager on the same docker network: proxy.

2024-12-30_19-40

2024-12-30_19-41

Basically how I do it for all docker apps I want to access over the network.

Verba is accessible via my localip:8111 or via the FQDN i set in NPM. Both work.

However when I access it over the internet and - for instance - change the theme to dark, it resets to light whenever I do a page refresh. I get a 'fresh´ instance every time. Files I upload via local ip are not visible when accessing over the internet.

@thomashacker
Copy link
Collaborator

I think it's related to this issue #353
The workaround for now is to delete the custom middleware logic completely. Working on a fix for this 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigating Bugs that are still being investigated whether they are valid
Projects
None yet
Development

No branches or pull requests

3 participants