Fastest one. The idea is to run SSR script, get function with sensitive args and run it.
iso
object has Isolate *v8go.Isolate
and RenderScript *v8go.UnboundScript
(it was compiled before).
// renderer.go
// ...
func (r *Renderer) Render(urlPath string) (string, error) {
iso := r.pool.Get()
defer r.pool.Put(iso)
ctx := v8go.NewContext(iso.Isolate)
defer ctx.Close()
iso.RenderScript.Run(ctx)
renderCmd := fmt.Sprintf(`ssrRender("%s")`, urlPath)
val, err := ctx.RunScript(renderCmd, r.ssrScriptName)
if err != nil {
if jsErr, ok := err.(*v8go.JSError); ok {
err = fmt.Errorf("%v", jsErr.StackTrace)
}
return "", nil
}
return val.String(), nil
}
// entry-server.ts
// ...
function ssrRender(url: string) {
return render(url).then((html) => {
return html
})
}
(globalThis as any).ssrRender = ssrRender