Exemplo n.º 1
0
func runServer(c *cli.Context) {
	kit := utils.NewKit(c, conf)
	kit.Engine = gin.Default()

	kit.Engine.StaticFS("/static", &assetfs.AssetFS{
		Asset:    data.Asset,
		AssetDir: data.AssetDir,
		Prefix:   "static",
	})

	kit.Engine.Use(func(c *gin.Context) {
		c.Set("kit", kit)
	})

	// Avoid favicon react handling
	kit.Engine.GET("/favicon.ico", func(c *gin.Context) {
		c.Redirect(301, "/static/images/favicon.ico")
	})

	kit.Engine.GET("/api/v1/conf", api.ConfHandler)

	kit.Engine.Use(func(c *gin.Context) {
		id, _ := uuid.NewV4()
		c.Set("uuid", id)
	})
	react.Bind(kit)
	utils.Must(kit.Engine.Run(":" + kit.Conf.UString("port")))
}
Exemplo n.º 2
0
// Loads bundle.js to context
func newDuktapeContext(engine *gin.Engine) *duktape.Context {
	vm := duktape.New()
	vm.PevalString(`var console = {log:print,warn:print,error:print,info:print}`)
	fetch.Define(vm, engine)
	app, err := data.Asset("static/build/bundle.js")
	utils.Must(err)
	fmt.Println("static/build/bundle.js loaded")
	if err := vm.PevalString(string(app)); err != nil {
		derr := err.(*duktape.Error)
		fmt.Printf("\n\n\n%v\n%v\n\n\n", derr.FileName, derr.LineNumber)
		panic(derr.Message)
	}
	vm.PopN(vm.GetTop())
	return vm
}