-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CSP Layouts #338
Comments
@rbugajewski , Hey, I have read those issues from you, thanks for all the suggestions. As you said, I mainly use drogon in REST API backends, so its support for views is still very primitive, and I will carefully consider these suggestions, thank you very much. |
@rbugajewski I added layouts support for csp files. You could use the hw.csp
global_layout.csp <header>
<h1>Welcome to my homepage</h1>
</header>
[[]]
<footer>
<p>Contact information: <a href="[email protected]">[email protected]</a>.</p>
</footer> The |
Thanks for adding support for layouts, this is a well-maintained project. Layouts work on my setup, but I’m a little bit confused and not sure if this is something Drogon-related or if I’ve screwed something up. I have added the following directive to one of my template files (
I also have a filed called The problem I see is that the generated Index class makes my layout name lowercase ( Is it expected behavior that layouts always have to be lowercase? |
Sorry, this is a wrong conversion. I fixed it. |
I just discovered that the dynamic view loading mechanism doesn’t generate the layout portion for the templates while the regular compilation works. Is this something you can confirm or did I break my local setup, @an-tao? |
You could find the code in templates:
Sorry, I didn't think carefully about the scenario where the layout view is dynamically loaded, the |
@rbugajewski , please check the PR #378 , thanks. |
@an-tao I checked out the
While the dynamic compilation generates:
Furthermore the
My wild guess is that this is somehow configuration or path related. By the way: What is the easiest way / workflow to debug the framework itself? |
This line means that the drogon_ctl used by 'dynamic loading component is a old version one, please make sure the drogon_ctl installed in your system is the latest.
You could configure drogon with |
Stupid me 😅 This was indeed the case, I forgot to copy the new executable to
Thanks for the info, I’ll have to check my IDE setup, because my breakpoints currently disappear. I have copied the executable and now the layout gets processed as expected, but I got a crash after saving & reloading the index page:
The controller is a very simple one:
|
I figured out what my problem initial problem was: Do you know how I can debug the |
I don't know how to debug a extranal command (drogon_ctl) calls when dynamically loading, I think you can debug drogon_ctl separately. I am thinking about compiling the I tested the dynamic loading more today, I found a strange thing on MacOS when compiling drogon in debug mode, if there were more than one views being loaded dynamically, the view first dynamically loaded by my test project couldn't be updated again when it was chanaged. It was be compiled and loaded successfully, but the the registerClass method is called by a static val in To reproduce the above issue, create two views for dynamic loading, compile drogon and your test project in debug mode, set the log level to |
@an-tao I also observed that something is a little bit off. My IDE is currently compiling the project with I also use Live.js to get an almost instant reload in the browser to make development easier. Live.js polls the website by sending a What I discovered is that this mechanism doesn’t work for the first page edited with dynamic loading enabled, but a manual refresh actually works. I also think there is room for improvement for dynamic loading / development mode, but I have the feeling that this should be planned instead of being hacked together. After I thought a little bit through it, layouts & dynamic load are a little bit more complicated. Currently when you change the layout of the page, you still have to recompile & relaunch the application (also changing the page that extends from the layout still uses the old layout). I thought of putting the pages, layouts & their relations into a tree-like structure. Before compilation the path to the upper-most layout should be traversed and recompilation of all dependencies in the right order triggered. Another improvement that is crucial for me to make Drogon work with more classic Server-Side-Rendered (SSR) setups would be to cache the state of dynamically compiled views between runs. Example: Currently when I change one line in a controller, I have to recompile. This by itself is fine. But when I have dynamic layouts enabled all of them will be regenerated on the next run. For sites with more than a dozen pages you have to wait a long time until you can see the results of your changes again. In this case storing hashes of the |
@rbugajewski Apart from the aforementioned exceptions, dynamic updates of the layout worked fine in my test environment (with dev branch of drogon), compared to ordinary views, the layout view is nothing special, I really can't think of any reason to explain why it can't be updated via dynamic loading, so I guess your problem is probably the problem I mentioned earlier, you can try to compile your project using release mode to confirm this. |
@an-tao It looks like there are still some low hanging fruits regarding layouts on macOS. In some cases I get an empty page when Drogon returns a |
auto templ = DrTemplateBase::newTemplate(layoutName);
if(!templ) return "";
HttpViewData data;
auto str = std::move(a_tmp_stream.str());
if(!str.empty() && str[str.length()-1] == '\n') str.resize(str.length()-1);
data[""] = std::move(str);
return templ->genText(data); Maybe in some race conditions the |
@an-tao Thanks to your info I was able to analyze the issue. I had some Everything works fine now after I deleted the |
I tested this today and I confirm that this happens on my installation (macOS Catalina, clang version 11.0.0 (clang-1100.0.33.17)). As this is only the first page that is affected, I created a page called |
It is currently possible to concatenate multiple CSP files into one view by using the
<%view%>
directive. Whenever I have a website with the same header & footer, but different main content, I can add a new CSP file for the main content, then integrate the header & footer with two<%view%>
statements.The problem here is that now I have to keep in mind to add both, the header, and the footer, to every page. Another issue is that now, after the header & footer are separated, they do no longer represent a full HTML file.
I would like to see some support for layouts (which would ideally reside in a separate directory). In this case I could say that a specific page extends from a layout (which is a CSP page by itself). The layout page should be an (almost) well formed HTML page that has a placeholder / statement where the concrete page will be substituted.
The text was updated successfully, but these errors were encountered: