Skip to content

Commit

Permalink
update vite and build to work with main.py
Browse files Browse the repository at this point in the history
* add nonce to allow script execution
* dump json in python to get a valid one for Vue
* update html to handle missing values
* add vite plugin to compilate message in order to fix unsafe-eval CSP
* update static paths from build templates in order to work with flask static folder delivery
* start handling Vue.js home page to flask
  • Loading branch information
syrk4web committed Jul 2, 2024
1 parent b00e3c6 commit 1d4214a
Show file tree
Hide file tree
Showing 15 changed files with 469 additions and 314 deletions.
31 changes: 23 additions & 8 deletions src/client/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,34 @@ async function setBuildTempToUI() {
if (err) {
console.log(err);
}
let updateData = "";
let updateData = data;
// I want to remove the first "/" for href="/css", href="/js", href="/img", href="/favicon", src="/assets" or src="/js"
const regexPaths = /href="\/(css|js|img|favicon)|src="\/(assets|js)/g;
updateData = data.replace(regexPaths, (match) => {
return match.replace("/", "");
});

// For each <script> tag, I want to add nonce="{{ script_nonce }}" inside it
const regexScript = /<script/g;
updateData = updateData.replace(regexScript, (match) => {
return match.replace(
"<script",
'<script nonce="{{ script_nonce }}" '
);
});

// remove everything after <body> tag
const bodyIndex = data.indexOf("<body>");
const bodyIndex = updateData.indexOf("<body>");
// Add attributs

const attributs = `<body>
<div class="hidden" data-csrf-token={{ csrf_token() }}></div>\n
<div class="hidden" data-server-global={{data_server_global}}></div>\n
<div class="hidden" data-server-flash={{data_server_flash}}></div>\n
<div class="hidden" data-server-builder={{data_server_builder}}></div>\n
<div id="app"></div>\n</body>\n</html>`;
<div class="hidden" data-csrf-token="{{ csrf_token() }}"></div>\n
<div class="hidden" data-server-global="{{data_server_global if data_server_global else {}}}"></div>\n
<div class="hidden" data-server-flash="{{data_server_flash if data_server_flash else []}}"></div>\n
<div class="hidden" data-server-builder="{{data_server_builder}}"></div>\n
<div id="app"></div>\n</body>\n</html>`;
// insert the new content
updateData = updateData = data.substring(0, bodyIndex) + attributs;
updateData = updateData.substring(0, bodyIndex) + attributs;
fs.writeFileSync(
`${appTempDir}/${file}`,
updateData,
Expand Down
Loading

0 comments on commit 1d4214a

Please sign in to comment.