Use specific content-type options for each route
This commit is contained in:
parent
b304c9f3f4
commit
b1165a6180
2 changed files with 42 additions and 12 deletions
|
@ -19,6 +19,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/abcum/fibre"
|
||||
"github.com/abcum/fibre/mw"
|
||||
"github.com/abcum/surreal/db"
|
||||
"github.com/abcum/surreal/sql"
|
||||
)
|
||||
|
@ -107,6 +108,15 @@ func routes(s *fibre.Fibre) {
|
|||
return signup(c)
|
||||
})
|
||||
|
||||
s.Use(mw.Type(&mw.TypeOpts{
|
||||
AllowedContent: map[string]bool{
|
||||
"application/json": true,
|
||||
"application/cbor": true,
|
||||
"application/msgpack": true,
|
||||
"application/x-www-form-urlencoded": true,
|
||||
},
|
||||
}).PathIs("/signup"))
|
||||
|
||||
// --------------------------------------------------
|
||||
// Endpoints for authentication signin
|
||||
// --------------------------------------------------
|
||||
|
@ -119,6 +129,15 @@ func routes(s *fibre.Fibre) {
|
|||
return signin(c)
|
||||
})
|
||||
|
||||
s.Use(mw.Type(&mw.TypeOpts{
|
||||
AllowedContent: map[string]bool{
|
||||
"application/json": true,
|
||||
"application/cbor": true,
|
||||
"application/msgpack": true,
|
||||
"application/x-www-form-urlencoded": true,
|
||||
},
|
||||
}).PathIs("/signin"))
|
||||
|
||||
// --------------------------------------------------
|
||||
// Endpoints for import and exporting data
|
||||
// --------------------------------------------------
|
||||
|
@ -131,6 +150,12 @@ func routes(s *fibre.Fibre) {
|
|||
return importer(c)
|
||||
})
|
||||
|
||||
s.Use(mw.Type(&mw.TypeOpts{
|
||||
AllowedContent: map[string]bool{
|
||||
"application/octet-stream": true,
|
||||
},
|
||||
}).PathIs("/export", "/import"))
|
||||
|
||||
// --------------------------------------------------
|
||||
// Endpoints for submitting sql queries
|
||||
// --------------------------------------------------
|
||||
|
@ -147,6 +172,14 @@ func routes(s *fibre.Fibre) {
|
|||
return c.Send(200, res)
|
||||
})
|
||||
|
||||
s.Use(mw.Type(&mw.TypeOpts{
|
||||
AllowedContent: map[string]bool{
|
||||
"application/json": true,
|
||||
"application/cbor": true,
|
||||
"application/msgpack": true,
|
||||
},
|
||||
}).PathIs("/sql"))
|
||||
|
||||
s.Get("/sql", func(c *fibre.Context) error {
|
||||
|
||||
if err := c.Upgrade(); err != nil {
|
||||
|
@ -327,4 +360,13 @@ func routes(s *fibre.Fibre) {
|
|||
|
||||
})
|
||||
|
||||
s.Use(mw.Type(&mw.TypeOpts{
|
||||
AllowedContent: map[string]bool{
|
||||
"application/json": true,
|
||||
"application/cbor": true,
|
||||
"application/msgpack": true,
|
||||
"application/vnd.api+json": true,
|
||||
},
|
||||
}).PathBegsWith("/key/"))
|
||||
|
||||
}
|
||||
|
|
12
web/web.go
12
web/web.go
|
@ -54,18 +54,6 @@ func Setup(opts *cnf.Options) (err error) {
|
|||
AllowedLength: 1 << 20,
|
||||
}))
|
||||
|
||||
// Check body type
|
||||
|
||||
s.Use(mw.Type(&mw.TypeOpts{
|
||||
AllowedContent: map[string]bool{
|
||||
"application/json": true,
|
||||
"application/cbor": true,
|
||||
"application/msgpack": true,
|
||||
"application/octet-stream": true,
|
||||
"application/x-www-form-urlencoded": true,
|
||||
},
|
||||
}))
|
||||
|
||||
// Run the server
|
||||
|
||||
if len(opts.Cert.Crt) == 0 || len(opts.Cert.Key) == 0 {
|
||||
|
|
Loading…
Reference in a new issue