gocraft / web

Go Router + Middleware. Your Contexts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StaticMiddleware() is not working

yvasiyarov opened this issue · comments

Hello,

I've created simple application:

package main

import (
    "github.com/gocraft/web"
    "net/http"
)
type Context struct{

}


func main() {
    router := web.New(Context{}).
        Middleware(web.LoggerMiddleware).
        Middleware(web.ShowErrorsMiddleware).
        Middleware(web.StaticMiddleware("public"))
    http.ListenAndServe("localhost:8080", router)
}

in the same folder I have "public" directory with "index.html" file inside.
If I make "http://localhost:8080/index.html" request, I got "404 page not found"
any idea why ?

Have you tried "./public" and made sure that your "public" directory is in the same directory as your main file? I ask because I made the mistake of having my main.go in a "bin/" directory and couldn't understand why static wasn't working. Obviously, I needed to ask for "../public" in that case.

@yvasiyarov lmk if andrioid's advice didn't help. This wfm.