maddyblue/esc

can't serve index.html

amitu opened this issue · 4 comments

$ esc -o static.go index.html style.css
http.Handle("/", http.FileServer(FS(Debug)))

I can access /style.css but not /index.html.

[amitu@AmitUs-MacBook-Air martd (master ✗)]$ curl -I localhost:54321/index.html
HTTP/1.1 301 Moved Permanently
Location: ./
Date: Mon, 24 Nov 2014 08:29:07 GMT
Content-Type: text/plain; charset=utf-8

[amitu@AmitUs-MacBook-Air martd (master ✗)]$ curl -I localhost:54321/
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Date: Mon, 24 Nov 2014 08:29:15 GMT
Content-Length: 19

[amitu@AmitUs-MacBook-Air martd (master ✗)]$ curl -I localhost:54321/style.css
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 1378
Content-Type: text/css; charset=utf-8
Date: Mon, 24 Nov 2014 08:31:26 GMT

[amitu@AmitUs-MacBook-Air martd (master ✗)]$

Interesting. The Go file server removes "/index.html", performs a redirect, and then requests the file again with "/index.html" appended, but only if the file system interface advertises "/" as a directory. esc needs to add directory listings to its abilities (see in my blog post how I said esc doesn't yet do that). I had no idea it was required to be able to serve index.html. Will fix soon.

If I manually add a field dir bool in file stuct, update the isDir() and add an entry for / in data, and set dir flag, it starts serving:

[amitu@AmitUs-MacBook-Air martd (master ✗)]$ curl -i localhost:54321/
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Date: Mon, 24 Nov 2014 10:00:10 GMT
Content-Length: 13

<pre>
</pre>

This is not the content of my index.html.

This should work.

Does. Thanks. :-)