Archived
Commit of all existing code.
This commit is contained in:
Executable
+11
@@ -0,0 +1,11 @@
|
||||
package cmd
|
||||
|
||||
import "github.com/urfave/cli/v2"
|
||||
|
||||
func intFlag(name string, value int, usage string) *cli.IntFlag {
|
||||
return &cli.IntFlag{
|
||||
Name: name,
|
||||
Value: value,
|
||||
Usage: usage,
|
||||
}
|
||||
}
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"frostfire.io/dir2opdspse/app/routes"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/urfave/cli/v2"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var Serve = cli.Command{
|
||||
Name: "serve",
|
||||
Usage: "Starts the webserver",
|
||||
Description: "Start the Flux webserver. That's all you need to run.",
|
||||
Action: runServe,
|
||||
Flags: []cli.Flag{
|
||||
intFlag("port, p", 3000, "Web server port"),
|
||||
},
|
||||
}
|
||||
|
||||
func runServe(c *cli.Context) error {
|
||||
r := mux.NewRouter()
|
||||
|
||||
fs := http.FileServer(http.Dir("books/"))
|
||||
r.PathPrefix("/manga/").Handler(http.StripPrefix("/manga", fs))
|
||||
|
||||
routes.Init(c, r)
|
||||
|
||||
srv := &http.Server{
|
||||
Handler: r,
|
||||
Addr: ":" + strconv.Itoa(c.Int("port")),
|
||||
WriteTimeout: 15 * time.Second,
|
||||
ReadTimeout: 15 * time.Second,
|
||||
}
|
||||
|
||||
return srv.ListenAndServe()
|
||||
}
|
||||
Reference in New Issue
Block a user