Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework server rendering approach #10

Merged
merged 12 commits into from
Oct 25, 2023
Prev Previous commit
Next Next commit
Use strings.builder for server render node calls
  • Loading branch information
natewong1313 committed Oct 24, 2023
commit 27fc3b590ee7a5d57177ab15a278ff56d0629d59
12 changes: 9 additions & 3 deletions internal/reactbuilder/render.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package reactbuilder

import (
"errors"
"os/exec"
"strings"
)

func RenderReactToHTML(serverRenderJSFilePath string) (string, error) {
cmd := exec.Command("node", serverRenderJSFilePath)
out, err := cmd.CombinedOutput()
stdOut := new(strings.Builder)
stdErr := new(strings.Builder)
cmd.Stdout = stdOut
cmd.Stderr = stdErr
err := cmd.Run()
if err != nil {
return "", err
return "", errors.New(stdErr.String())
}
return string(out), nil
return stdOut.String(), nil
}