Adding Redux to project, updating to version 0.1.0

This commit is contained in:
2023-10-06 23:13:57 +00:00
parent d4f2474436
commit ec020257e0
18 changed files with 16724 additions and 48 deletions

View File

@ -6,7 +6,7 @@ import (
)
func LoadEnv() {
err := godotenv.Load(".env")
err := godotenv.Load("../../.env")
if err != nil {
log.Fatal("Error loading .env file")
}

View File

@ -0,0 +1,37 @@
package utils
import (
"fmt"
"os/exec"
)
func GetPreloadedState() string {
// Set the path to the jsxToString.js file
jsFilePath := "./web/getstate/getPreloadedState.js"
// Create the command to run Node.js with the jsxToString.js file
cmd := exec.Command("node", jsFilePath)
// Get a pipe to the standard input of the Node.js process
stdin, err := cmd.StdinPipe()
if err != nil {
fmt.Println(err)
return ""
}
// Write the URL parameter to the standard input of the Node.js process
//fmt.Fprintf(stdin, "%s\n", url)
// Close the standard input pipe
stdin.Close()
// Get the output and error of the Node.js process
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(err)
return string(output)
}
// Return the output of the Node.js process
return string(output)
}

View File

@ -7,7 +7,7 @@ import (
func JsxToString(url string) string {
// Set the path to the jsxToString.js file
jsFilePath := "./web/utils/tsxToString.js"
jsFilePath := "./web/conversion/tsxToString.js"
// Create the command to run Node.js with the jsxToString.js file
cmd := exec.Command("node", jsFilePath, url)

View File

@ -32,6 +32,7 @@ func RegisterHandlers(e *echo.Echo, paths []string) {
//return c.File(filePath)
url := c.Request().URL.String()
component := utils.JsxToString(url)
preloadedState := utils.GetPreloadedState();
html := `<!DOCTYPE html>
<html lang="es">
<head>
@ -47,9 +48,9 @@ func RegisterHandlers(e *echo.Echo, paths []string) {
</head>
<body>
<div id="app">`+ component +`</div>
<!-- <script>
window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState).replace(/</g, '\\u003c')}
</script> -->
<script>
window.__PRELOADED_STATE__ = JSON.stringify(`+ preloadedState+`).replace(/</g, '\\u003c')
</script>
<script src="assets/app-frontend.js" type="text/javascript"></script>
<script src="assets/vendor-vendors.js" type="text/javascript"></script>
</body>