mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Added HTTPS session support
This commit is contained in:
parent
68ecbdd595
commit
2101b706d3
10
README.md
10
README.md
@ -35,6 +35,16 @@ cowyo
|
||||
|
||||
and it will start a server listening on `0.0.0.0:8050`. To view it, just go to http://localhost:8050 (the server prints out the local IP for your info if you want to do LAN networking). You can change the port with `-port X`, and you can listen *only* on localhost using `-host localhost`.
|
||||
|
||||
### Running with TLS
|
||||
|
||||
Specify a matching pair of SSL Certificate and Key to run cowyo using https. Cowyo will now run in a secure session.
|
||||
|
||||
*N.B. Let's Encrypt is a CA that signs free and signed certificates.*
|
||||
|
||||
```
|
||||
cowyo --cert "/path/to/server.crt" --key "/p/t/server.key"
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
*cowyo* is straightforward to use. Here are some of the basic features:
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func serve(host, port string) {
|
||||
func serve(host, port, crt_path, key_path string, TLS bool) {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
router := gin.Default()
|
||||
router.HTMLRender = loadTemplates("index.tmpl")
|
||||
@ -32,8 +32,12 @@ func serve(host, port string) {
|
||||
router.DELETE("/oldlist", handleClearOldListItems)
|
||||
router.DELETE("/listitem", deleteListItem)
|
||||
|
||||
if TLS {
|
||||
http.ListenAndServeTLS(host+":"+port, crt_path, key_path, router)
|
||||
} else {
|
||||
router.Run(host + ":" + port)
|
||||
}
|
||||
}
|
||||
|
||||
func loadTemplates(list ...string) multitemplate.Render {
|
||||
r := multitemplate.New()
|
||||
|
23
main.go
23
main.go
@ -24,11 +24,22 @@ func main() {
|
||||
pathToData = c.GlobalString("data")
|
||||
os.MkdirAll(pathToData, 0755)
|
||||
host := c.GlobalString("host")
|
||||
crt_f := c.GlobalString("cert") // crt flag
|
||||
key_f := c.GlobalString("key") // key flag
|
||||
if host == "" {
|
||||
host = GetLocalIP()
|
||||
}
|
||||
TLS := false
|
||||
if crt_f != "" && key_f != "" {
|
||||
TLS = true
|
||||
}
|
||||
if TLS {
|
||||
fmt.Printf("\nRunning cowyo server (version %s) at https://%s:%s\n\n", version, host, c.GlobalString("port"))
|
||||
} else {
|
||||
fmt.Printf("\nRunning cowyo server (version %s) at http://%s:%s\n\n", version, host, c.GlobalString("port"))
|
||||
serve(c.GlobalString("host"), c.GlobalString("port"))
|
||||
}
|
||||
fmt.Println(TLS)
|
||||
serve(c.GlobalString("host"), c.GlobalString("port"), c.GlobalString("cert"), c.GlobalString("key"), TLS)
|
||||
return nil
|
||||
}
|
||||
app.Flags = []cli.Flag{
|
||||
@ -52,6 +63,16 @@ func main() {
|
||||
Value: "8050",
|
||||
Usage: "port to use",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "cert",
|
||||
Value: "",
|
||||
Usage: "Absolute Path to SSL Public Cert",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "key",
|
||||
Value: "",
|
||||
Usage: "Aboslute Path to corresponding private key",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "debug, d",
|
||||
Usage: "turn on debugging",
|
||||
|
Loading…
Reference in New Issue
Block a user