You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

87 lines
2.1 KiB

package main
import (
"fmt"
"git.ouxuan.net/3136352472/go-service-template/jsruntime"
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskutils"
"github.com/gin-gonic/gin"
"io/ioutil"
"log"
"os"
"path/filepath"
)
func main() {
os.Chdir("domino")
r := gin.Default()
mainFile := filepath.Join(hskutils.GetSelfFilePath(), "govue", "govue.js")
useFileName := filepath.Join(hskutils.GetSelfFilePath(), "static", "use.js")
render, err := jsruntime.NewJsRuntime(mainFile, useFileName, jsruntime.Relys{
jsruntime.Rely{
Variable: "domino",
FileName: "./index.js",
},
jsruntime.Rely{
Variable: "init",
FileName: filepath.Join("..", "govue", "init.js"),
},
jsruntime.Rely{
Variable: "Promise",
FileName: filepath.Join("..", "govue", "promise.js"),
},
jsruntime.Rely{
Variable: "axios",
FileName: filepath.Join("..", "govue", "axios.js"),
},
jsruntime.Rely{
Variable: "Vue",
FileName: "./vue.js",
},
})
if err != nil {
panic(err)
}
r.NoRoute(func(context *gin.Context) {
path := filepath.Join(hskutils.GetSelfFilePath(), "static", context.Request.URL.Path)
fi, err := os.Stat(path)
if err != nil {
context.Writer.Write([]byte("页面不存在"))
return
} else if fi.IsDir() {
path = filepath.Join(path, "index.html")
}
raw, err := ioutil.ReadFile(path)
if !hskutils.PathExists(path) || err != nil {
context.Writer.Write([]byte("页面不存在"))
return
}
if filepath.Ext(path) != ".html" {
//log.Println("ext", filepath.Ext(path))
context.Writer.WriteHeader(200)
context.Writer.Write(raw)
return
}
log.Println(context.Request.URL.RawPath)
log.Println(context.Request.URL.RawQuery)
log.Println(context.Request.URL.RequestURI())
log.Println(context.Request.URL.String())
log.Println(context.Request.URL.Scheme)
log.Println(context.Request.Host)
log.Println(context.Request.RequestURI)
log.Println(context.Request.Proto)
result := render.Render(fmt.Sprintf("http://%s%s", context.Request.Host, context.Request.RequestURI), string(raw))
context.Writer.WriteHeader(200)
context.Writer.Write([]byte(result))
return
})
r.Run("127.0.0.1:8080")
}