diff --git a/web/routes.go b/web/routes.go index 5eb15304..f075f7a5 100644 --- a/web/routes.go +++ b/web/routes.go @@ -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/")) + } diff --git a/web/web.go b/web/web.go index 08fab5a3..9aefb19d 100644 --- a/web/web.go +++ b/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 {