pitr / gig

Gemini framework
MIT License
61 stars 5 forks source link

"Serving static files" not working as advertised #9

Closed Salty2021 closed 3 years ago

Salty2021 commented 3 years ago

Issue Description

The following method of serving static file

g.Static("/test.txt", "content/test.txt")

does not seem to work.

Checklist

Expected behaviour

Server running on localhost. When client requests gemini://localhost/test.txt, the server shall return the content of the text file located at content/test.txt. The directory structure used is as follows:

--$GOPATH (dir)
       |--src (dir)
             |--gig_server (dir)
                    |--content (dir)
                    |       |--test.txt
                    |       |--imgs (dir)
                    |                 |--tuxedo_cat.jpg
                    |--main.go
                    |--go.mod
                    |--gig_server (executable)
                    |--my.crt
                    |--my.key

Actual behaviour

The server returns "not found", and logs the following

time="2021-06-18T06:09:03+00:00" path=/test.txt status=51 duration=0.06 error=Not Found

Steps to reproduce

As described above.

Working code to debug

content of main.go:

package main

import "github.com/pitr/gig"

func main() {
        g := gig.Default()

        g.Static("/test.txt", "content/test.txt")

        g.Run("my.crt", "my.key")
}

content of test.txt:

Come find me!

Version/commit

go version go1.16.5 darwin/amd64. gig version 0.9.8

Note:

When the "static file" designated is a directory, it works fine. e.g.,

g.Static("/imgs", "content/imgs")

works when client requests gemini://localhost/imgs/tuxedo_cat.jpg.

pitr commented 3 years ago

I clarified Static section in README. To serve single files, you need to use g.File instead. Static("/test.txt",...) registers /test.txt/*.