Directory tree:
.
├── main.go
└── web
├── app.go
└── views
├── index.html
└── js
└── app.jsx
This works:
package main
import (
"net/http"
)
func main() {
http.Handle("/", http.FileServer(http.Dir("./web/views")))
http.ListenAndServe(":3000", nil)
}
But this returns 404 page not found
:
main.go:
package main
import (
"{dir with main.go}/web"
)
func main() {
web.StartHttp()
}
app.go:
package web
import (
"fmt"
"net/http"
)
func StartHttp() {
fmt.Println("STARTHTTP - CHECK 01")
http.Handle("/", http.FileServer(http.Dir("./views")))
http.ListenAndServe(":3000", nil)
}
The terminal prints STARTHTTP - CHECK 01
, so the StartHttp()
function is called, and the terminal asks to allow incoming network connections, so the http server seems to be listening on the port.
Is there some type of context not being passed to the other package?