mirror of
https://github.com/alerta/alerta.git
synced 2025-01-30 03:33:59 +00:00
1538a97717
* Add alerts and action forwarder plugin for federated setups * Add tests for forwarder plugin
31 lines
883 B
Python
31 lines
883 B
Python
from functools import wraps
|
|
from urllib.parse import urljoin
|
|
|
|
from flask import current_app, request
|
|
|
|
|
|
def jsonp(func):
|
|
"""Wraps JSONified output for JSONP requests."""
|
|
@wraps(func)
|
|
def decorated(*args, **kwargs):
|
|
callback = request.args.get('callback', False)
|
|
if callback:
|
|
data = str(func(*args, **kwargs).data)
|
|
content = str(callback) + '(' + data + ')'
|
|
mimetype = 'application/javascript'
|
|
return current_app.response_class(content, mimetype=mimetype)
|
|
else:
|
|
return func(*args, **kwargs)
|
|
return decorated
|
|
|
|
|
|
def absolute_url(path: str = '') -> str:
|
|
try:
|
|
base_url = current_app.config.get('BASE_URL', request.url_root)
|
|
except Exception:
|
|
base_url = '/'
|
|
return urljoin(base_url, path) if path else base_url
|
|
|
|
|
|
def base_url():
|
|
return absolute_url(path='')
|