mirror of
https://github.com/rjNemo/go-pass-gen
synced 2026-06-06 10:56:40 +00:00
34 lines
974 B
Go
34 lines
974 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
"github.com/go-chi/cors"
|
|
)
|
|
|
|
type Server struct {
|
|
Router *chi.Mux
|
|
}
|
|
|
|
func NewServer() *Server {
|
|
s := &Server{Router: chi.NewRouter()}
|
|
s.Router.Use(middleware.Logger)
|
|
s.Router.Use(cors.Handler(cors.Options{
|
|
// AllowedOrigins: []string{"https://foo.com"}, // Use this to allow specific origin hosts
|
|
AllowedOrigins: []string{"https://*", "http://*"},
|
|
// AllowOriginFunc: func(r *http.Request, origin string) bool { return true },
|
|
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
|
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
|
|
ExposedHeaders: []string{"Link"},
|
|
AllowCredentials: false,
|
|
MaxAge: 300, // Maximum value not ignored by any of major browsers
|
|
}))
|
|
s.routes()
|
|
return s
|
|
}
|
|
|
|
func (s Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
s.Router.ServeHTTP(w, r)
|
|
}
|