fix: harden UCE runtime and starter
This commit is contained in:
@@ -1,29 +1,63 @@
|
||||
#load "lib/app.uce"
|
||||
|
||||
#load "lib/app.uce"
|
||||
|
||||
DTree starter_router_result(String file, String param = "")
|
||||
{
|
||||
DTree result;
|
||||
result["file"] = file;
|
||||
if(param != "")
|
||||
result["param"] = param;
|
||||
return(result);
|
||||
}
|
||||
|
||||
DTree starter_router_resolve(Request& context)
|
||||
{
|
||||
String lpath = context.call["route"]["l_path"].to_string();
|
||||
if(lpath == "")
|
||||
return(DTree());
|
||||
|
||||
String exact = "views/" + lpath + ".uce";
|
||||
if(file_exists(exact))
|
||||
return(starter_router_result(exact));
|
||||
|
||||
String directory_index = "views/" + lpath + "/index.uce";
|
||||
if(file_exists(directory_index))
|
||||
return(starter_router_result(directory_index));
|
||||
|
||||
auto parts = split(lpath, "/");
|
||||
while(parts.size() > 1)
|
||||
{
|
||||
String param = parts.back();
|
||||
parts.pop_back();
|
||||
String parent = join(parts, "/");
|
||||
String parent_index = "views/" + parent + "/index.uce";
|
||||
if(file_exists(parent_index))
|
||||
return(starter_router_result(parent_index, param));
|
||||
}
|
||||
|
||||
return(DTree());
|
||||
}
|
||||
|
||||
RENDER(Request& context)
|
||||
{
|
||||
app_init(context);
|
||||
|
||||
DTree resolved = app_resolve_view(context);
|
||||
DTree resolved = starter_router_resolve(context);
|
||||
|
||||
ob_start();
|
||||
if(resolved["file"].to_string() != "")
|
||||
{
|
||||
if(resolved["param"].to_string() != "")
|
||||
context.call["app"]["route"]["param"] = resolved["param"];
|
||||
unit_render(resolved["file"].to_string(), context);
|
||||
context.call["route"]["param"] = resolved["param"];
|
||||
print(component(resolved["file"].to_string(), context));
|
||||
}
|
||||
else
|
||||
{
|
||||
app_not_found("The requested page does not exist.", context);
|
||||
<>
|
||||
<section class="card">
|
||||
<h1>404 Not Found</h1>
|
||||
<p><?= context.call["app"]["error"].to_string() ?></p>
|
||||
</section>
|
||||
</>
|
||||
DTree notfound_props;
|
||||
notfound_props["message"] = "The requested page does not exist.";
|
||||
print(component("components/basic/notfound", notfound_props, context));
|
||||
}
|
||||
|
||||
String main_html = ob_get_close();
|
||||
context.call["app"]["fragments"]["main"] = main_html;
|
||||
app_render_page(context);
|
||||
context.call["fragments"]["main"] = main_html;
|
||||
print(component("themes/page", context));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user