Skip to content

Commit

Permalink
Merge pull request #750 from shimilgithub/api-refactor
Browse files Browse the repository at this point in the history
Separate CMS Module
  • Loading branch information
shimilgithub authored Jan 11, 2024
2 parents 758af43 + 191a857 commit b8560eb
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ To run all the testcases, from the folder vachan-api/app run the command

```python -m pytest```

For runing testselectively, refer [pytest docs](https://docs.pytest.org/en/stable/usage.html#specifying-tests-selecting-tests)
For runing testselectively, refer [pytest docs](https://docs.pytest.org/en/stable/usage.html#specifying-tests-selecting-tests)
36 changes: 30 additions & 6 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
app = FastAPI(title="Vachan-API", version="2.0.0",
description=f"The server application that provides APIs to interact \
with the underlying Databases and modules in Vachan-Engine. \
\n • For Vachan-CMS docs: {root_url}/v2/cms/rest/docs,\
\n • For Vachan-TBT docs: {root_url}/v2/text/translate/token-based/docs")
template = Jinja2Templates(directory="templates")
app.mount("/static", StaticFiles(directory="static"), name="static")
Expand Down Expand Up @@ -241,13 +242,36 @@ def test(request: Request,db_: Session = Depends(get_db)):
"/v2/files/usfm/to/{output_format}"
]

# def custom_openapi():
# '''Modify the auto generated openapi schema for API docs'''
# openapi_schema = get_openapi(title="Vachan-API", version="2.0.0",
# description=f"The server application that provides APIs to interact \
# with the underlying Databases and modules in Vachan-Engine. \
# <br> • <a href=\"{root_url}/v2/text/translate/token-based/docs\" > Vachan-TBT docs </a>",
# routes=app.routes)

# # Add version information to specific endpoints
# for path, path_data in openapi_schema["paths"].items():
# for _, method_data in path_data.items():
# if path in beta_endpoints:
# # Set endpoints as experimental in the API-docs
# method_data.setdefault("x-experimental", True)

# return openapi_schema

def custom_openapi():
'''Modify the auto generated openapi schema for API docs'''
openapi_schema = get_openapi(title="Vachan-API", version="2.0.0",
description=f"The server application that provides APIs to interact \
with the underlying Databases and modules in Vachan-Engine. \
<br> • <a href=\"{root_url}/v2/text/translate/token-based/docs\" > Vachan-TBT docs </a>",
routes=app.routes)
'''Modify the auto-generated OpenAPI schema for API docs'''
cms_href = "<a href=\"{root_url}/v2/cms/rest/docs\" > Vachan-CMS-REST docs </a>"
tbt_href = "<a href=\"{root_url}/v2/text/translate/token-based/docs\" > Vachan-TBT docs </a>"

openapi_schema = get_openapi(
title="Vachan-API",
version="2.0.0",
description=f"The server application that provides APIs to interact\
with the underlying Databases and modules in Vachan-Engine.\
<br> • {cms_href} <br> • {tbt_href}",
routes=app.routes
)

# Add version information to specific endpoints
for path, path_data in openapi_schema["paths"].items():
Expand Down
36 changes: 32 additions & 4 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
kratos-postgresd:
image: postgres:9.6
ports:
- "5432:5432"
- "5438:5432"
expose:
- 5432
restart: always
Expand Down Expand Up @@ -91,7 +91,7 @@ services:
- 5432
ports:
# HOST:CONTAINER
- "5433:5432"
- "5439:5432"
networks:
- VE-network
volumes:
Expand Down Expand Up @@ -207,7 +207,35 @@ services:
- deployment
networks:
- VE-network


vachan-cms-rest:
image: athulyams/vachan-cms-rest:v2.0.1
# ports:
# - "8004:8004"
expose:
- 8005
command: uvicorn main:app --host 0.0.0.0 --port 8005
restart: always
environment:
- VACHAN_POSTGRES_HOST=vachan-db
- VACHAN_POSTGRES_PORT=5432
- VACHAN_POSTGRES_USER=${VACHAN_POSTGRES_USER:-postgres}
- VACHAN_POSTGRES_PASSWORD=${VACHAN_POSTGRES_PASSWORD:-password}
- VACHAN_POSTGRES_DATABASE=${VACHAN_POSTGRES_DATABASE:-vachan_dev}
- VACHAN_POSTGRES_SCHEMA=vachan_cms_rest
- VACHAN_LOGGING_LEVEL=INFO
- VACHAN_DOMAIN=${VACHAN_DOMAIN:-http://localhost}
- VACHAN_CMS_DOMAIN=http://vachan-api
volumes:
- logs-vol:/app/logs
depends_on:
- vachan-db
profiles:
- local-run
- deployment
networks:
- VE-network

vachan-tbt:
image: kavitha3797/vachan-tbt:v2.0.1
expose:
Expand Down Expand Up @@ -266,7 +294,7 @@ services:
web-server-local:
image: nginx:latest
ports:
- 80:80
- 82:80
restart: always
expose:
- 80
Expand Down
4 changes: 4 additions & 0 deletions docker/nginx/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ server {
proxy_set_header X-Forwarded-Proto $scheme;
}

location /v2/cms/rest/ {
proxy_pass http://vachan-cms-rest:8005;
}

location /v2/text/translate/token-based/ {
proxy_pass http://vachan-tbt:8003;
}
Expand Down
4 changes: 4 additions & 0 deletions docker/nginx/prod/app.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ server {
proxy_pass http://vachan-cms-graphql:8004;
}

location /v2/cms/rest/ {
proxy_pass http://vachan-cms-rest:8005;
}

location /v2/text/translate/token-based/ {
proxy_pass http://vachan-tbt:8003;
}
Expand Down

0 comments on commit b8560eb

Please sign in to comment.