~shulhan/ciigo

d5542dc8956c5d084817b60ed7451870c7175865 — Shulhan 4 months ago d71ceab
all: initialize memfs using New

When memfs not initialized using New, the [memfs.MemFS.PathNodes] will
be nil.
This cause any Get on new file will return 404.
1 files changed, 11 insertions(+), 8 deletions(-)

M server.go
M server.go => server.go +11 -8
@@ 31,17 31,20 @@ func newServer(opts *ServeOptions) (srv *server, err error) {
	var logp = `newServer`

	if opts.Mfs == nil {
		opts.Mfs = &memfs.MemFS{
			Opts: &memfs.Options{
				Root:     opts.Root,
				Excludes: defExcludes,
			},
		}
		opts.IsDevelopment = true
		var mfsopts = &memfs.Options{
			Root:      opts.Root,
			Excludes:  defExcludes,
			TryDirect: true,
		}
		opts.Mfs, err = memfs.New(mfsopts)
		if err != nil {
			return nil, fmt.Errorf(`%s: %w`, logp, err)
		}
	} else {
		opts.Mfs.Opts.TryDirect = opts.IsDevelopment
	}

	opts.Mfs.Opts.TryDirect = opts.IsDevelopment

	srv = &server{
		opts: *opts,
	}