9
0
mirror of https://github.com/donlon/cloudflare-error-page.git synced 2025-12-24 17:29:16 +00:00

editor/web: show status code from params

This commit is contained in:
Anthony Donlon
2025-12-23 01:41:18 +08:00
parent 8be87415fe
commit d39409c0ca
2 changed files with 5 additions and 2 deletions

View File

@@ -6,8 +6,9 @@ const port = 3000;
// Define a route for GET requests to the root URL
<%# TODO: format to JS-style object (key w/o parens) _%>
<% const errorCode = params.error_code || 500 _%>
app.get('/', (req, res) => {
res.status(500).send(render_cf_error_page(<%-JSON.stringify(params, null, 2).replaceAll('\n', '\n ')%>));
res.status(<%= /\d{3}/.test(errorCode + '') ? errorCode : 500 %>).send(render_cf_error_page(<%-JSON.stringify(params, null, 2).replaceAll('\n', '\n ')%>));
});
// Start the server and listen on the specified port

View File

@@ -13,6 +13,8 @@ const paramsArg = JSON.stringify(params, (key, value) => {
.replace(`"${randomKey}true"`, 'True')
.replace(`"${randomKey}false"`, 'False')
.replace(`"${randomKey}null"`, 'None')
const errorCode = params.error_code || 500
_%>
from flask import Flask
from cloudflare_error_page import render as render_cf_error_page
@@ -23,7 +25,7 @@ app = Flask(__name__)
@app.route('/')
def index():
# Render the error page
return render_cf_error_page(<%- paramsArg.replaceAll('\n', '\n ') %>), 500
return render_cf_error_page(<%- paramsArg.replaceAll('\n', '\n ') %>), <%= /\d{3}/.test(errorCode + '') ? errorCode : 500 %>
if __name__ == '__main__':
app.run(debug=True, port=5000)