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

View file

@ -6,22 +6,15 @@
<title>Cozy (McFly)</title>
<script server:setup>
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>
</my-head>
<body>
<h1>{{ appName }} - {{McFly.hello}}</h1>
<form method="post">
<input required type="url" id="url" name="url" />
<form method="get">
<input required type="url" id="url" name="url" value={{ url }} />
<button type="submit">Extract</button>
<ul>
<li>
URL: {{ McFly.event.body.url }}
</li>
<li>
Method: {{ McFly.event.method }}
</li>
</ul>
</form>
</body>
</html>