diff --git a/editor/resources/index.html b/editor/resources/index.html
index 905c26a..cb6eec7 100644
--- a/editor/resources/index.html
+++ b/editor/resources/index.html
@@ -41,7 +41,8 @@
}
})
- const initialConfig = {
+ // can be changed if specified by '?from='
+ let initialConfig = {
"html_title": "cloudflare.com | 500: Internal server error",
"title": "Internal server error",
"error_code": 500,
@@ -139,6 +140,30 @@
},
};
+ const urlParams = new URLSearchParams(window.location.search);
+ const defaultPresetName = urlParams.get('from');
+ if (defaultPresetName && defaultPresetName.indexOf('/') < 0) {
+ fetch(`../s/${defaultPresetName}`, {
+ headers: {
+ 'Accept': 'application/json'
+ },
+ })
+ .then(response => {
+ if (!response.ok) {
+ throw new Error('failed to get preset');
+ }
+ return response.json();
+ })
+ .then(result => {
+ if (result.status != 'ok') {
+ return
+ }
+ console.log(result.parameters)
+ initialConfig = result.parameters
+ loadConfig(initialConfig);
+ })
+ }
+
/* Utilities */
function $(id) { return document.getElementById(id); }
diff --git a/editor/server/share.py b/editor/server/share.py
index bf06752..de950b4 100644
--- a/editor/server/share.py
+++ b/editor/server/share.py
@@ -57,9 +57,17 @@ def create():
@bp.get('/')
def get(name: str):
+ accept = request.headers.get('Accept', '')
+ is_json = 'application/json' in accept
+
item = db.session.query(models.Item).filter_by(name=name).first()
if not item:
- return abort(404)
+ if is_json:
+ return jsonify({
+ 'status': 'not-found'
+ })
+ else:
+ return abort(404)
params = item.params
params = {
**params,
@@ -73,4 +81,11 @@ def get(name: str):
'text': 'CF Error Page Editor',
'link': f'https://virt.moe/cloudflare-error-page/editor/?from={name}',
}
- return render_cf_error_page(params=params, allow_html=False, use_cdn=True), 200
+
+ if is_json:
+ return jsonify({
+ 'status': 'ok',
+ 'parameters': params,
+ })
+ else:
+ return render_cf_error_page(params=params, allow_html=False, use_cdn=True), 200