mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
make serving files as optional feature.
This commit is contained in:
parent
7fb977faa4
commit
d78f98e78e
@ -30,7 +30,7 @@ func (Server) Init(cmd *cobra.Command) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.PersistentFlags().String("static", "./www", "path to neko client files to serve")
|
cmd.PersistentFlags().String("static", "", "path to neko client files to serve")
|
||||||
if err := viper.BindPFlag("static", cmd.PersistentFlags().Lookup("static")); err != nil {
|
if err := viper.BindPFlag("static", cmd.PersistentFlags().Lookup("static")); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ func New(WebSocketManager types.WebSocketManager, ApiManager types.ApiManager, c
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if conf.Static != "" {
|
||||||
fs := http.FileServer(http.Dir(conf.Static))
|
fs := http.FileServer(http.Dir(conf.Static))
|
||||||
router.Get("/*", func(w http.ResponseWriter, r *http.Request) {
|
router.Get("/*", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if _, err := os.Stat(conf.Static + r.RequestURI); os.IsNotExist(err) {
|
if _, err := os.Stat(conf.Static + r.RequestURI); os.IsNotExist(err) {
|
||||||
@ -48,6 +49,7 @@ func New(WebSocketManager types.WebSocketManager, ApiManager types.ApiManager, c
|
|||||||
fs.ServeHTTP(w, r)
|
fs.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
router.NotFound(endpoint.Handle(func(w http.ResponseWriter, r *http.Request) error {
|
router.NotFound(endpoint.Handle(func(w http.ResponseWriter, r *http.Request) error {
|
||||||
return &endpoint.HandlerError{
|
return &endpoint.HandlerError{
|
||||||
|
Loading…
Reference in New Issue
Block a user