-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
46 lines (40 loc) · 1.34 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"net/http"
"strings"
"github.com/gorilla/csrf"
"github.com/qor/qor/utils"
"github.com/sunwukonga/qor-scbn/config"
"github.com/sunwukonga/qor-scbn/config/admin"
"github.com/sunwukonga/qor-scbn/config/api"
_ "github.com/sunwukonga/qor-scbn/config/i18n"
"github.com/sunwukonga/qor-scbn/config/routes"
_ "github.com/sunwukonga/qor-scbn/db/migrations"
)
func main() {
mux := http.NewServeMux()
mux.Handle("/", routes.Router())
admin.Admin.MountTo("/admin", mux)
admin.ResellerAdmin.MountTo("/reseller_panel", mux)
admin.Widgets.WidgetSettingResource.IndexAttrs("Name")
api.API.MountTo("/api", mux)
admin.Filebox.MountTo("/downloads", mux)
for _, path := range []string{"system", "javascripts", "stylesheets", "images"} {
mux.Handle(fmt.Sprintf("/%s/", path), utils.FileServer(http.Dir("public")))
}
fmt.Printf("Listening on: %v\n", config.Config.Port)
skipCheck := func(h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
if !strings.HasPrefix(r.URL.Path, "/auth") {
r = csrf.UnsafeSkipCheck(r)
}
h.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
handler := csrf.Protect([]byte("3693f371bf91487c99286a777811bd4e"), csrf.Secure(false))(mux)
if err := http.ListenAndServe(fmt.Sprintf(":%d", config.Config.Port), skipCheck(handler)); err != nil {
panic(err)
}
}