-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathapp.go
68 lines (57 loc) · 1.9 KB
/
app.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package actions
import (
"context"
"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/buffalo-pop/pop/popmw"
"github.com/gobuffalo/envy"
contenttype "github.com/gobuffalo/mw-contenttype"
paramlogger "github.com/gobuffalo/mw-paramlogger"
tokenauth "github.com/gobuffalo/mw-tokenauth"
"github.com/gobuffalo/x/sessions"
"github.com/ossn/fixme_backend/models"
"github.com/rs/cors"
)
// ENV is used to help switch settings based on where the
// application is being run. Default is "development".
var ENV = envy.Get("GO_ENV", "development")
var app *buffalo.App
// App is where all routes and middleware for buffalo
// should be defined. This is the nerve center of your
// application.
func App(ctx context.Context) *buffalo.App {
if app == nil {
app = buffalo.New(buffalo.Options{
WorkerOff: true,
Context: ctx,
Env: ENV,
SessionStore: sessions.Null{},
PreWares: []buffalo.PreWare{
cors.Default().Handler,
},
Prefix: "/api",
SessionName: "_fixme_backend_session",
})
if ENV == "development" {
// Log request parameters (filters apply).
app.Use(paramlogger.ParameterLogger)
}
// Set the request content type to JSON
app.Use(contenttype.Set("application/json"))
// Wraps each request in a transaction.
// c.Value("tx").(*pop.Connection)
// Remove to disable this.
app.Use(popmw.Transaction(models.DB))
app.GET("/projects", ProjectsResource{}.List)
app.GET("/repositories", RepositoriesResource{}.List)
app.GET("/issues", IssuesResource{}.ListOpen)
app.GET("/issues-count", IssuesResource{}.Count)
app.POST("/login", AdminsResource{}.Login)
admin := app.Group("/admin")
admin.Use(tokenauth.New(tokenauth.Options{}))
admin.Resource("/projects", ProjectsResource{})
admin.Resource("/repositories", RepositoriesResource{})
admin.Resource("/issues", IssuesResource{})
admin.Resource("/users", AdminsResource{})
}
return app
}