golemcloud / golem

Golem is an open source durable computing platform that makes it easy to build and deploy highly reliable distributed systems.
https://learn.golem.cloud/
Apache License 2.0
530 stars 59 forks source link

Make string interpolation flexible #1047

Closed afsalthaj closed 2 weeks ago

afsalthaj commented 3 weeks ago

In response to https://discord.com/channels/1134448700572319785/1134448701260169249/1300769907755061268

and tracked as part of https://github.com/golemcloud/golem/issues/1035 which is currently in progress

Previously I tested the html str responded from worker, however, not inlining HTML within Rib. Things failed when inlining within a string interpolation, as indicated by discord user.

Rib

let style = "font-family: Arial, sans-serif; display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg, #1e3c72, #2a5298); color: #ffffff; text-align: center; padding: 20px;";

let user: u64 = request.path.user-id;

let body = "
  <!DOCTYPE html>
     <html>
       <head>
      </head>
      <body style='${style}'>
         <div>
           <h1>Welcome to Golem Cloud!</h1>
           <p style='font-size: 1.5em;'>Hello, User ID: ${user}</p>
           <p style='color: #dcdcdc;'>Explore your cart contents and more on this personalized page.</p>
       </div>
    </body>
  </html>"

{Content-Type: "text/html", status: 200u64, body: body}

Result

image

NOTE: Having a complex HTML within Rib within API Definition JSON is really hard. Everything has to be 1 line. Or else use golem-cloud console Rib editor.

https://github.com/afsalthaj/golem-worker-gateway-examples/blob/main/html/api-definition.json