Skip to content
Snippets Groups Projects
Commit e2096c9f authored by Christian Boettcher's avatar Christian Boettcher
Browse files

create static now can configure the api url from env variable

parent e39e6b7e
No related branches found
No related tags found
No related merge requests found
......@@ -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
// 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment