Skip to content

Commit

Permalink
chore: update staging frontend url (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna authored Sep 24, 2023
1 parent 4d73864 commit e638c72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
memory: 500Mi
env:
- name: "BASE_URL_FRONTEND"
value: "https://homologation.basedosdados.org"
value: "https://staging.basedosdados.org"
- name: "BASE_URL_API"
value: "https://staging.api.basedosdados.org"
envFrom:
Expand Down
18 changes: 9 additions & 9 deletions basedosdados_api/core/views/dataset_redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@

from basedosdados_api.api.v1.models import CloudTable, Dataset

URL_MAPPING = {
"localhost:8001": "localhost:3000",
"api.basedosdados.org": "basedosdados.org",
"staging.api.basedosdados.org": "staging.basedosdados.org",
"development.api.basedosdados.org": "development.basedosdados.org",
}


class DatasetRedirectView(View):
"""View to redirect old dataset urls."""

def get(self, request, *args, **kwargs):
"""Redirect to new dataset url."""
full_url = request.build_absolute_uri() # noqa
full_url = request.build_absolute_uri()
domain = urlparse(full_url).netloc

dataset = request.GET.get("dataset")
dataset_slug = dataset.replace("-", "_")
BASE_URL = {
"localhost:8001": "localhost:3000",
"development.api.basedosdados.org": "development.basedosdados.org",
"staging.api.basedosdados.org": "homologation.basedosdados.org",
"api.basedosdados.org": "basedosdados.org",
}
redirect_domain = BASE_URL[domain]
redirect_domain = URL_MAPPING[domain]

try:
redirect_url = CloudTable.objects.filter(gcp_dataset_id=dataset_slug).first()
if not redirect_url:
raise CloudTable.DoesNotExist
redirect_url = f"http://{redirect_domain}/dataset/{str(redirect_url.table.dataset.id)}"
except CloudTable.DoesNotExist:
# não tem cloud table, procura pelo nome do dataset
try:
new_ds = Dataset.objects.filter(slug__icontains=dataset_slug).first()
redirect_url = f"http://{redirect_domain}/dataset/{str(new_ds.id)}"
Expand Down

0 comments on commit e638c72

Please sign in to comment.