From b46a8a2b9ded7a08dafe8b4ad0c081279508b61b Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Wed, 21 Dec 2022 17:39:22 +0800 Subject: [PATCH] fix(docker): api address incorrect issue --- bin/docker-init.sh | 3 ++ bin/docker-start-master.sh | 43 ----------------------------- bin/update_docker_js_api_address.py | 24 ++++++++++++++++ 3 files changed, 27 insertions(+), 43 deletions(-) delete mode 100644 bin/docker-start-master.sh create mode 100644 bin/update_docker_js_api_address.py diff --git a/bin/docker-init.sh b/bin/docker-init.sh index 452348b5..3f49f824 100755 --- a/bin/docker-init.sh +++ b/bin/docker-init.sh @@ -1,3 +1,6 @@ #!/bin/bash +# replace default api path to new one +python /app/bin/update_docker_js_api_address.py + crawlab-server server diff --git a/bin/docker-start-master.sh b/bin/docker-start-master.sh deleted file mode 100644 index e3720814..00000000 --- a/bin/docker-start-master.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -# NOTE: deprecated - -# replace env -indexPath=/app/dist/index.html -if test -z "$CRAWLAB_BASE_URL"; then - : -else - sed -i "s?/js/?${CRAWLAB_BASE_URL}/js/?g" ${indexPath} - sed -i "s?/css/?${CRAWLAB_BASE_URL}/css/?g" ${indexPath} - sed -i "s/ >/var/log/weed.log 2>&1 & diff --git a/bin/update_docker_js_api_address.py b/bin/update_docker_js_api_address.py new file mode 100644 index 00000000..1fe780ec --- /dev/null +++ b/bin/update_docker_js_api_address.py @@ -0,0 +1,24 @@ +import os + +dir_path = '/app/dist/assets' + +for file_name in os.listdir(dir_path): + if not file_name.endswith('.js'): + continue + + file_path = os.path.join(dir_path, file_name) + + api_url = 'http://localhost:8000' + + with open(file_path, 'r') as f: + content = f.read() + + if api_url not in content: + continue + + content = content.replace(api_url, '/api') + + with open(file_path, 'w') as f: + f.write(content) + + print(f'replaced api url in file: {file_name}')