Serve Vuejs ด้วย Golang
Require
- github.com/labstack/echo/v4 # framework api golang
- vuejs
Frontend (vuejs)
- Create
sh
$ vue create frontend
$ cd frontend
- Edit Yarn build
"scripts": {
...
"build": "vue-cli-service build --dest ../views",
...
},
$ yarn build
Golang
$ go mod init <project>
import (
"github.com/labstack/echo/v4"
)
func main() {
e := echo.New()
e.Use(middleware.Static("views"))
e.File("*", "views/index.html")
e.Logger.Fatal(e.Start(":9000"))
}
package main
import (
"github.com/labstack/echo/v4"
)
func main() {
e := echo.New()
e.Use(middleware.Static("views"))
e.File("*", "views/index.html")
e.Logger.Fatal(e.Start(":9000"))
}
$ go run .
GitHub - jaedsadadotme/go-vue