-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from PDOK/cleanup
Cleanup
- Loading branch information
Showing
17 changed files
with
82 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package engine | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"github.com/go-chi/chi/v5" | ||
"github.com/go-chi/chi/v5/middleware" | ||
"github.com/go-chi/cors" | ||
) | ||
|
||
func newRouter(version string, enableTrailingSlash bool, enableCORS bool) *chi.Mux { | ||
router := chi.NewRouter() | ||
router.Use(middleware.RealIP) // should be first middleware | ||
router.Use(middleware.Logger) // log to console | ||
router.Use(middleware.Recoverer) // catch panics and turn into 500s | ||
router.Use(middleware.GetHead) // support HEAD requests https://docs.ogc.org/is/17-069r4/17-069r4.html#_http_1_1 | ||
if enableTrailingSlash { | ||
router.Use(middleware.StripSlashes) | ||
} | ||
if enableCORS { | ||
router.Use(cors.Handler(cors.Options{ | ||
AllowedOrigins: []string{"*"}, | ||
AllowedMethods: []string{http.MethodGet, http.MethodHead, http.MethodOptions}, | ||
AllowedHeaders: []string{HeaderRequestedWith}, | ||
ExposedHeaders: []string{HeaderContentCrs, HeaderLink}, | ||
AllowCredentials: false, | ||
MaxAge: int((time.Hour * 24).Seconds()), | ||
})) | ||
} | ||
// implements https://gitdocumentatie.logius.nl/publicatie/api/adr/#api-57 | ||
router.Use(middleware.SetHeader(HeaderAPIVersion, version)) | ||
router.Use(middleware.Compress(5, CompressibleMediaTypes...)) // enable gzip responses | ||
return router | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.