test notification
This commit is contained in:
parent
07dc830160
commit
cf46844a4e
19
app.py
19
app.py
@ -120,6 +120,25 @@ def proxy_save_subscription():
|
||||
except requests.exceptions.RequestException as e:
|
||||
return jsonify({"error": str(e)}), 502
|
||||
|
||||
@app.route('/send-test-notification', methods=['POST'])
|
||||
def proxy_send_test_notification():
|
||||
"""Proxies the request to send a test notification to the backend."""
|
||||
if not session.get("logged_in"):
|
||||
return jsonify({'error': 'Unauthorized'}), 401
|
||||
|
||||
backend_url = f"{app.config['BASE_URL']}/send-test-notification"
|
||||
credentials = base64.b64decode(session["auth_credentials"]).decode()
|
||||
username, password = credentials.split(":", 1)
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
backend_url,
|
||||
auth=requests.auth.HTTPBasicAuth(username, password)
|
||||
)
|
||||
return Response(response.content, status=response.status_code, mimetype=response.headers['Content-Type'])
|
||||
except requests.exceptions.RequestException as e:
|
||||
return jsonify({"error": str(e)}), 502
|
||||
|
||||
@app.route("/home")
|
||||
@cache.cached(timeout=60)
|
||||
def home() -> str:
|
||||
|
@ -46,7 +46,7 @@
|
||||
</main>
|
||||
|
||||
<footer class="bg-dark text-white text-center py-3 mt-5">
|
||||
<p>Version: {{ version }}</p>
|
||||
<p>Version: <a href="#" id="version-link">{{ version }}</a></p>
|
||||
</footer>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
|
||||
@ -65,6 +65,15 @@
|
||||
}, function(err) {
|
||||
console.log('ServiceWorker registration failed: ', err);
|
||||
});
|
||||
|
||||
document.getElementById('version-link').addEventListener('click', function(event) {
|
||||
event.preventDefault();
|
||||
fetch('/send-test-notification', {
|
||||
method: 'POST'
|
||||
}).then(response => response.json())
|
||||
.then(data => console.log(data.message))
|
||||
.catch(err => console.error('Error sending test notification:', err));
|
||||
});
|
||||
}
|
||||
|
||||
function askPermission(registration) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user