Exemplo n.º 1
0
func initRouters() {
	m.Get("/$qrcode", routers.Qrcode)
	m.Get("/*", routers.NewStaticHandler(gcfg.root))
	m.Post("/*", routers.NewUploadHandler(gcfg.root))
	m.Get("/$zip/*", routers.NewZipDownloadHandler(gcfg.root))
	m.Get("/$plist/*", routers.NewPlistHandler(gcfg.root))
	m.Get("/$ipaicon/*", routers.NewIpaIconHandler(gcfg.root))
	m.Get("/$ipa/*", routers.IPAHandler)
	ReloadProxy := func(w http.ResponseWriter, r *http.Request) {
		log.Println("Debug, Hot reload", r.Host)
		resp, err := http.Get("http://localhost:3000" + r.RequestURI)
		if err != nil {
			http.Error(w, err.Error(), 500)
			return
		}
		defer resp.Body.Close()
		io.Copy(w, resp.Body)
	}
	// HTTP Basic Authentication
	userpass := strings.SplitN(gcfg.httpauth, ":", 2)
	if len(userpass) == 2 {
		user, pass := userpass[0], userpass[1]
		m.Use(auth.Basic(user, pass))
	}
	if gcfg.gzip {
		m.Use(gzip.Gziper())
	}
	m.Get("/-/:rand(.*).hot-update.:ext(.*)", ReloadProxy)
	m.Get("/-/:name(.*).bundle.js", ReloadProxy)
}
Exemplo n.º 2
0
func init() {
	m = macaron.Classic()
	m.Use(modules.Public)
	m.Use(modules.Renderer)
	m.Use(gzip.Gziper())

	flag.IntVar(&gcfg.port, "port", 8000, "Which port to listen")
	flag.StringVar(&gcfg.root, "root", ".", "Watched root directory for filesystem events, also the HTTP File Server's root directory")
	flag.BoolVar(&gcfg.private, "private", false, "Only listen on lookback interface, otherwise listen on all interface")
	flag.StringVar(&gcfg.httpauth, "auth", "", "Basic Authentication (ex: username:password)")
}
Exemplo n.º 3
0
func Gziper() macaron.Handler {
	macaronGziper := gzip.Gziper()

	return func(ctx *macaron.Context) {
		requestPath := ctx.Req.URL.RequestURI()
		// ignore datasource proxy requests
		if strings.HasPrefix(requestPath, "/api/datasources/proxy") {
			return
		}

		ctx.Invoke(macaronGziper)
	}
}
Exemplo n.º 4
0
func init() {
	m = macaron.Classic()
	m.Use(modules.Public)
	m.Use(modules.Renderer)
	m.Use(gzip.Gziper())

	kingpin.HelpFlag.Short('h')
	kingpin.Flag("port", "Port to listen").Default("8000").IntVar(&gcfg.port)
	kingpin.Flag("root", "File root directory").Default(".").StringVar(&gcfg.root)
	kingpin.Flag("private", "Only listen on loopback address").BoolVar(&gcfg.private)
	kingpin.Flag("httpauth", "HTTP basic auth (ex: user:pass)").Default("").StringVar(&gcfg.httpauth)
	kingpin.Flag("cert", "TLS cert.pem").StringVar(&gcfg.cert)
	kingpin.Flag("key", "TLS key.pem").StringVar(&gcfg.key)
	kingpin.Flag("ftp", "Enable FTP support").BoolVar(&gcfg.ftp)
	kingpin.Flag("ftp-port", "FTP listen port").Default("2121").IntVar(&gcfg.ftpPort)
	kingpin.Flag("ftp-auth", "FTP auth (ex: user:pass)").Default("admin:123456").StringVar(&gcfg.ftpAuth)
}
Exemplo n.º 5
0
// newMacaron initializes Macaron instance.
func newMacaron() *macaron.Macaron {
	m := macaron.New()
	if !setting.DisableRouterLog {
		m.Use(macaron.Logger())
	}
	m.Use(macaron.Recovery())
	if setting.EnableGzip {
		m.Use(gzip.Gziper())
	}
	if setting.Protocol == setting.FCGI {
		m.SetURLPrefix(setting.AppSubUrl)
	}
	m.Use(macaron.Static(
		path.Join(setting.StaticRootPath, "public"),
		macaron.StaticOptions{
			SkipLogging: setting.DisableRouterLog,
		},
	))
	m.Use(macaron.Static(
		setting.AvatarUploadPath,
		macaron.StaticOptions{
			Prefix:      "avatars",
			SkipLogging: setting.DisableRouterLog,
		},
	))
	m.Use(macaron.Renderer(macaron.RenderOptions{
		Directory:  path.Join(setting.StaticRootPath, "templates"),
		Funcs:      []gotmpl.FuncMap{template.Funcs},
		IndentJSON: macaron.Env != macaron.PROD,
	}))

	localeNames, err := bindata.AssetDir("conf/locale")
	if err != nil {
		log.Fatal(4, "Fail to list locale files: %v", err)
	}
	localFiles := make(map[string][]byte)
	for _, name := range localeNames {
		localFiles[name] = bindata.MustAsset("conf/locale/" + name)
	}
	m.Use(i18n.I18n(i18n.Options{
		SubURL:          setting.AppSubUrl,
		Files:           localFiles,
		CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
		Langs:           setting.Langs,
		Names:           setting.Names,
		DefaultLang:     "en-US",
		Redirect:        true,
	}))
	m.Use(cache.Cacher(cache.Options{
		Adapter:       setting.CacheAdapter,
		AdapterConfig: setting.CacheConn,
		Interval:      setting.CacheInternal,
	}))
	m.Use(captcha.Captchaer(captcha.Options{
		SubURL: setting.AppSubUrl,
	}))
	m.Use(session.Sessioner(setting.SessionConfig))
	m.Use(csrf.Csrfer(csrf.Options{
		Secret:     setting.SecretKey,
		SetCookie:  true,
		Header:     "X-Csrf-Token",
		CookiePath: setting.AppSubUrl,
	}))
	m.Use(toolbox.Toolboxer(m, toolbox.Options{
		HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
			&toolbox.HealthCheckFuncDesc{
				Desc: "Database connection",
				Func: models.Ping,
			},
		},
	}))
	m.Use(middleware.Contexter())
	return m
}