@@ -27,16 +27,34 @@ def coerce_to_list(cls, v):
2727_PREBUILT_CDN_URL = f'https://cdn.jsdelivr.net/npm/@pydantic/fastui-prebuilt@{ _PREBUILT_VERSION } /dist/assets'
2828
2929
30- def prebuilt_html (title : str = '' ):
30+ def prebuilt_html (
31+ * ,
32+ title : str = '' ,
33+ api_root_url : _t .Union [str , None ] = None ,
34+ api_path_mode : _t .Union [_t .Literal ['append' , 'query' ], None ] = None ,
35+ api_path_strip : _t .Union [str , None ] = None ,
36+ ) -> str :
3137 """
3238 Returns a simple HTML page which includes the FastUI react frontend, loaded from https://www.jsdelivr.com/.
3339
3440 Arguments:
3541 title: page title
42+ api_root_url: the root URL of the API backend, which will be used to get data, default is '/api'.
43+ api_path_mode: whether to append the page path to the root API request URL, or use it as a query parameter,
44+ default is 'append'.
45+ api_path_strip: string to remove from the start of the page path before making the API request.
3646
3747 Returns:
3848 HTML string which can be returned by an endpoint to serve the FastUI frontend.
3949 """
50+ meta_extra = []
51+ if api_root_url is not None :
52+ meta_extra .append (f'<meta name="fastui:APIRootUrl" content="{ api_root_url } " />' )
53+ if api_path_mode is not None :
54+ meta_extra .append (f'<meta name="fastui:APIPathMode" content="{ api_path_mode } " />' )
55+ if api_path_strip is not None :
56+ meta_extra .append (f'<meta name="fastui:APIPathStrip" content="{ api_path_strip } " />' )
57+ meta_extra_str = '\n ' .join (meta_extra )
4058 # language=HTML
4159 return f"""\
4260 <!doctype html>
@@ -47,6 +65,7 @@ def prebuilt_html(title: str = ''):
4765 <title>{ title } </title>
4866 <script type="module" crossorigin src="{ _PREBUILT_CDN_URL } /index.js"></script>
4967 <link rel="stylesheet" crossorigin href="{ _PREBUILT_CDN_URL } /index.css">
68+ { meta_extra_str }
5069 </head>
5170 <body>
5271 <div id="root"></div>
0 commit comments