aboutsummaryrefslogtreecommitdiff
path: root/httpd.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-12-21 08:56:21 +0700
committerShulhan <ms@kilabit.info>2021-12-21 08:56:21 +0700
commit51af8aca85c8b2a264d99d3929b4259aa4717e7a (patch)
treeab7bf63472b8f92d8709190600a71f7882245a44 /httpd.go
parenta29a8c8396fc16af744a0abc86b5aca343aa620a (diff)
downloadrescached-51af8aca85c8b2a264d99d3929b4259aa4717e7a.tar.xz
all: move HTTP server option to Environment
Previously, the options for HTTP server initialized internally, which make it uneasy to changes the default rescached instance when running in development mode. This commit move the HTTP server initialization inside the Environment init method. If its nil, the init will set the default HTTP server options along with the Memfs.
Diffstat (limited to 'httpd.go')
-rw-r--r--httpd.go28
1 files changed, 1 insertions, 27 deletions
diff --git a/httpd.go b/httpd.go
index e3a64b0..b764d43 100644
--- a/httpd.go
+++ b/httpd.go
@@ -19,12 +19,9 @@ import (
"github.com/shuLhan/share/lib/dns"
liberrors "github.com/shuLhan/share/lib/errors"
libhttp "github.com/shuLhan/share/lib/http"
- "github.com/shuLhan/share/lib/memfs"
libnet "github.com/shuLhan/share/lib/net"
)
-var memFS *memfs.MemFS
-
const (
defHTTPDRootDir = "_www"
paramNameDomain = "domain"
@@ -52,30 +49,7 @@ func (r *response) Unwrap() error {
}
func (srv *Server) httpdInit() (err error) {
- env := &libhttp.ServerOptions{
- Options: memfs.Options{
- Root: defHTTPDRootDir,
- Includes: []string{
- `.*\.css`,
- `.*\.html`,
- `.*\.js`,
- `.*\.png`,
- },
- Development: srv.env.Debug >= 2,
- },
- Memfs: memFS,
- Address: srv.env.WUIListen,
- CORS: libhttp.CORSOptions{
- AllowOrigins: []string{
- "http://127.0.0.1:5000",
- },
- AllowHeaders: []string{
- libhttp.HeaderContentType,
- },
- },
- }
-
- srv.httpd, err = libhttp.NewServer(env)
+ srv.httpd, err = libhttp.NewServer(srv.env.HttpdOptions)
if err != nil {
return fmt.Errorf("newHTTPServer: %w", err)
}