Exemple #1
0
func main() {
	app := cli.NewApp()
	app.Name = version.FullName()
	app.Usage = "sample react app"
	app.Version = version.FullVersion()
	app.Author = "@ehazlett"
	app.Email = "github.com/ehazlett/react-base"
	app.Before = func(c *cli.Context) error {
		// enable debug
		if c.GlobalBool("debug") {
			log.SetLevel(log.DebugLevel)
			log.Debug("debug enabled")
		}

		return nil
	}
	app.Flags = []cli.Flag{
		cli.BoolFlag{
			Name:  "debug, D",
			Usage: "enable debug",
		},
	}
	app.Commands = []cli.Command{
		serve.Command,
	}

	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}
Exemple #2
0
func serveAction(c *cli.Context) {
	log.Infof("react-base %s", version.FullVersion())

	listenAddr := c.String("listen")
	publicDir := c.String("public-dir")

	globalMux := http.NewServeMux()
	// static handler
	globalMux.Handle("/", http.FileServer(http.Dir(publicDir)))

	s := &http.Server{
		Addr:    listenAddr,
		Handler: globalMux,
	}

	log.Infof("api serving: addr=%s", listenAddr)
	if err := s.ListenAndServe(); err != nil {
		log.Fatal(err)
	}

}