diff --git a/frontend/createStatic.py b/frontend/createStatic.py index b3f390ed668049bb3fd6fa4e7bd8ac7f600f01db..3c332375196d4d0eeaf344126f7325d626b24393 100644 --- a/frontend/createStatic.py +++ b/frontend/createStatic.py @@ -2,7 +2,10 @@ from jinja2 import Environment, FileSystemLoader import os import shutil -def render_template_to_site(): +API_URL_ENV_VARNAME = "DATACATALOG_API_URL" +API_URL_DEFAULT_VALUE = "http://localhost:8000/" + +def render_template_to_site(api_url=API_URL_DEFAULT_VALUE): ## copy javascript files to site folder src_files = os.listdir('frontend/js') dest = 'site/js' @@ -23,6 +26,16 @@ def render_template_to_site(): if os.path.isfile(full_name): shutil.copy(full_name, dest) + ## replace {{API_URL}} tag with actual api url from env + apicalls_file_path = 'site/js/apicalls.js' + api_tag = '{{API_URL}}' + with open(apicalls_file_path, 'r') as file: + filedata = file.read() + filedata = filedata.replace(api_tag, api_url) + with open(apicalls_file_path, 'w') as file: + file.write(filedata) + + ## render templates to site folder file_loader = FileSystemLoader('frontend/templates') env = Environment(loader=file_loader) @@ -52,4 +65,7 @@ def render_template_to_site(): f.write(html[file]) if __name__ == "__main__": - render_template_to_site() \ No newline at end of file + # if env variable is set, get api url from it, else use default + api_url = os.getenv(API_URL_ENV_VARNAME, API_URL_DEFAULT_VALUE) + # TODO if argument is there, set api url + render_template_to_site(api_url) \ No newline at end of file diff --git a/frontend/js/apicalls.js b/frontend/js/apicalls.js index 1d1e3c4e4ce1cbacdbfee2a74bff877d95f3c31b..57872fc8bff43364a7296354a62422828de7b7b9 100644 --- a/frontend/js/apicalls.js +++ b/frontend/js/apicalls.js @@ -1,5 +1,5 @@ // This file contains the api calls, as well as transform the data into html-text -var apiUrl = "http://zam024.fritz.box/api/"; // TODO switch out with real url, ideally during deployment +var apiUrl = "{{API_URL}}"; var allowedTypesList = []; // get data from url query variables