feat(cozy): set input value to received query url

This commit is contained in:
Ayo Ayco 2025-06-28 00:28:18 +02:00
parent 012db337ae
commit 0bf0a09300
2 changed files with 8 additions and 15 deletions

View file

@ -35,9 +35,6 @@ export async function evaluateServerScripts(_html: string, event: H3Event) {
method: event.method, method: event.method,
query, query,
body, body,
url: event.node.req.url,
statusCode: event.node.req.statusCode,
statusMessage: event.node.req.statusMessage,
} }
// console.log('>>> Event (from core)', McFlyGlobal) // console.log('>>> Event (from core)', McFlyGlobal)
@ -81,7 +78,6 @@ function evaluateServerScript(html: string) {
// @ts-ignore // @ts-ignore
.map((n) => n.declarations[0].id.name) //['declarations'][0].id.name) .map((n) => n.declarations[0].id.name) //['declarations'][0].id.name)
// const McFly=${JSON.stringify(McFlyGlobal)};
const constructor = `(function(){}.constructor)(\` const constructor = `(function(){}.constructor)(\`
const McFly=${JSON.stringify(McFlyGlobal)} const McFly=${JSON.stringify(McFlyGlobal)}
${script}; ${script};
@ -123,6 +119,10 @@ function evaluateServerScript(html: string) {
} }
}) })
// stringify objects
finalValue =
typeof finalValue === 'object' ? JSON.stringify(finalValue) : finalValue
html = html.replace(key, finalValue ?? '') html = html.replace(key, finalValue ?? '')
regex.lastIndex = -1 regex.lastIndex = -1
} }

View file

@ -6,22 +6,15 @@
<title>Cozy (McFly)</title> <title>Cozy (McFly)</title>
<script server:setup> <script server:setup>
const appName = "Cozy" const appName = "Cozy"
console.log('>>> Event (from app)', McFly.event.body) console.log('>>> Event (from app)', McFly.event)
const url = McFly.event.query.url
</script> </script>
</my-head> </my-head>
<body> <body>
<h1>{{ appName }} - {{McFly.hello}}</h1> <h1>{{ appName }} - {{McFly.hello}}</h1>
<form method="post"> <form method="get">
<input required type="url" id="url" name="url" /> <input required type="url" id="url" name="url" value={{ url }} />
<button type="submit">Extract</button> <button type="submit">Extract</button>
<ul>
<li>
URL: {{ McFly.event.body.url }}
</li>
<li>
Method: {{ McFly.event.method }}
</li>
</ul>
</form> </form>
</body> </body>
</html> </html>