From ed222714ce9e8ac7f6e4b9a0952bcd08f5108ff2 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sun, 25 Feb 2024 14:22:28 +1100 Subject: [PATCH] feat: Try to use a separate thread for tlsa generation --- main.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 5fe95b7..fe73afe 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ import json import render import secrets import nginx +import threading app = Flask(__name__) dotenv.load_dotenv() @@ -281,14 +282,17 @@ def publish(): if 'tlsa' in data: # Site is already published return redirect('/site') + def generate_ssl_and_write_nginx(): + tlsa = nginx.generate_ssl(i['name']) + data['tlsa'] = tlsa + with open(f'sites/{i["name"]}.json', 'w') as file: + json.dump(data, file) + nginx.write_nginx_conf(i['name']) - tlsa = nginx.generate_ssl(i['name']) - data['tlsa'] = tlsa - with open(f'sites/{i["name"]}.json', 'w') as file: - json.dump(data, file) - nginx.write_nginx_conf(i['name']) + threading.Thread(target=generate_ssl_and_write_nginx).start() return redirect('/site') + response = make_response(redirect('/')) response.set_cookie('auth', '', expires=0)