From 7437d91a2005f7f6a3f14467c3b20aac4a78566a Mon Sep 17 00:00:00 2001 From: Stacy Date: Mon, 9 Sep 2024 21:46:20 +0500 Subject: [PATCH 1/2] - fixed paths - added cors --- Dockerfile | 4 ++-- README.md | 5 ++--- app/entrypoint.sh | 5 ++--- app/main.py | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index aa9022d..d6d33e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN pip install fastapi uvicorn python-multipart RUN pip install streamlit rdflib -COPY ./app /app +COPY ./app /app_py COPY ./tests /tests -ENTRYPOINT ["bash", "/app/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["bash", "/app_py/entrypoint.sh"] diff --git a/README.md b/README.md index 6471e05..4c75534 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,11 @@ Based in https://github.com/SDSC-ORD/shacl ## How to use docker? ``` -docker build -t caviri/shaclapi:latest . +docker build -t caviri/shaclapi:latest . ``` ``` -docker run -it --rm -p 8000:15400 -p 8501:8501 caviri/shaclapi:latest -docker run -it --rm -p 7200:15400 -p 3000:8501 caviri/shaclapi:latest +docker run --rm -p 8501:15400 caviri/shaclapi:latest ``` ``` diff --git a/app/entrypoint.sh b/app/entrypoint.sh index 773953c..fa566b5 100644 --- a/app/entrypoint.sh +++ b/app/entrypoint.sh @@ -1,4 +1,3 @@ #!/bin/bash -nohup streamlit run /app/webapp/main.py & -python3 -m uvicorn app.main:app --host 0.0.0.0 --port 15400 - +nohup streamlit run /app_py/webapp/main.py & +python3 -m uvicorn app_py.main:app --host 0.0.0.0 --port 15400 diff --git a/app/main.py b/app/main.py index 820f1d1..5b6f31f 100644 --- a/app/main.py +++ b/app/main.py @@ -1,4 +1,5 @@ from fastapi import FastAPI, Request, Form +from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse import subprocess import os @@ -9,8 +10,25 @@ import json +origins = [ + "http://localhost:8051", + "http://localhost:8080", + "http://localhost:8000", + "http://127.0.0.1:8051", + "http://127.0.0.1:8080", + "http://127.0.0.1:8000", +] + app = FastAPI() +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + @app.get("/") def index(): return {"title": "Hello, welcome to the SHACL API"} From 89eddabb946616ea21d289ff55a64558cf2d2248 Mon Sep 17 00:00:00 2001 From: Stacy Date: Mon, 9 Sep 2024 22:22:26 +0500 Subject: [PATCH 2/2] - fixed cors --- app/main.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/app/main.py b/app/main.py index 5b6f31f..2543c73 100644 --- a/app/main.py +++ b/app/main.py @@ -10,20 +10,11 @@ import json -origins = [ - "http://localhost:8051", - "http://localhost:8080", - "http://localhost:8000", - "http://127.0.0.1:8051", - "http://127.0.0.1:8080", - "http://127.0.0.1:8000", -] - app = FastAPI() app.add_middleware( CORSMiddleware, - allow_origins=origins, + allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"],