Replies: 1 comment
-
|
The static middleware serves files as-is, so it won't help with injecting dynamic data. What you want is to handle Here's how I'd approach it: //go:embed all:dist
var staticFiles embed.FS
func main() {
e := echo.New()
// Serve index.html with dynamic data
e.GET("/", func(c echo.Context) error {
// Read the embedded index.html
content, err := staticFiles.ReadFile("dist/index.html")
if err != nil {
return err
}
// Inject your data (e.g., replace a placeholder)
html := strings.Replace(
string(content),
"<!--APP_CONFIG-->",
`<script>window.APP_CONFIG = {"apiUrl": "/api", "version": "1.0.0"}</script>`,
1,
)
return c.HTML(http.StatusOK, html)
})
// Serve other static assets normally
assetHandler := echo.WrapHandler(
http.FileServer(http.FS(staticFiles)),
)
e.GET("/dist/*", assetHandler)
e.Start(":8080")
}In your Vue <head>
<!--APP_CONFIG-->
</head>Then in your Vue app, access it via Alternatively, if you need more complex templating, you could use Go's |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I use the Static Middleware to serve a Vue Frontend which is embedded.
Is there a way to add some data to the index.html?
Beta Was this translation helpful? Give feedback.
All reactions