From 24fb9eb65b5cecd77a33840e0ec6dfaa17c98126 Mon Sep 17 00:00:00 2001 From: link2xt Date: Mon, 15 Jan 2024 11:06:35 +0000 Subject: [PATCH] Nicer /new URL for new accounts and redirect GET requests If user types in https://nine.testrun.org/new manually in the browser, at least Firefox and Brave suggest to open the app after following the redirect. --- cmdeploy/src/cmdeploy/genqr.py | 2 +- cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 | 18 ++++++++++++++++-- www/src/index.md | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cmdeploy/src/cmdeploy/genqr.py b/cmdeploy/src/cmdeploy/genqr.py index cc0bd51..5d84cf5 100644 --- a/cmdeploy/src/cmdeploy/genqr.py +++ b/cmdeploy/src/cmdeploy/genqr.py @@ -6,7 +6,7 @@ import io def gen_qr_png_data(maildomain): - url = f"DCACCOUNT:https://{maildomain}/cgi-bin/newemail.py" + url = f"DCACCOUNT:https://{maildomain}/new" image = gen_qr(maildomain, url) temp = io.BytesIO() image.save(temp, format="png") diff --git a/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 b/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 index 244eb27..09ef5cd 100644 --- a/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 +++ b/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 @@ -45,8 +45,22 @@ http { default_type text/plain; } - # add cgi-bin support - include /usr/share/doc/fcgiwrap/examples/nginx.conf; + location /new { + if ($request_method = GET) { + # Redirect to Delta Chat, + # which will in turn do a POST request. + return 301 dcaccount:https://{{ config.domain_name }}/new; + } + + fastcgi_pass unix:/run/fcgiwrap.socket; + include /etc/nginx/fastcgi_params; + fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/newemail.py; + } + + # Old URL for compatibility with e.g. printed QR codes. + location /cgi-bin/newemail.py { + return 301 /new; + } } # Redirect www. to non-www diff --git a/www/src/index.md b/www/src/index.md index 5308a2c..5469749 100644 --- a/www/src/index.md +++ b/www/src/index.md @@ -7,7 +7,7 @@ Welcome to instant, interoperable and [privacy-preserving](privacy.html) messagi 👉 **Tap** or scan this QR code to get a random `@{{config.mail_domain}}` e-mail address - + 🐣 **Choose** your Avatar and Name