mirror of
https://github.com/aleleba/create-react-go-ssr.git
synced 2025-07-28 18:48:13 -06:00
Adding Redux to project, updating to version 0.1.0
This commit is contained in:
@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func LoadEnv() {
|
||||
err := godotenv.Load(".env")
|
||||
err := godotenv.Load("../../.env")
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
}
|
||||
|
37
src/server/utils/getPreloadedState.go
Normal file
37
src/server/utils/getPreloadedState.go
Normal 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)
|
||||
}
|
@ -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)
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user