forked from x/ContextOS
mac mod context/web 支持https
This commit is contained in:
parent
44e9496f66
commit
5cb1f6e5ae
13
etc/init.sh
13
etc/init.sh
@ -1,12 +1,7 @@
|
|||||||
alias ~ context
|
|
||||||
alias ! history
|
|
||||||
alias @ config
|
|
||||||
alias $ cache
|
|
||||||
alias & server
|
|
||||||
alias * message
|
|
||||||
|
|
||||||
@debug on
|
@debug on
|
||||||
|
|
||||||
~mp
|
~web
|
||||||
listen :9090 ./
|
source etc/mp.sh
|
||||||
|
~mdb
|
||||||
|
& start
|
||||||
|
|
||||||
|
@ -478,9 +478,7 @@ var Index = &ctx.Context{Name: "cli", Help: "本地控制", // {{{
|
|||||||
delete(m.Target.Configs, arg[1])
|
delete(m.Target.Configs, arg[1])
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if _, ok := m.Target.Configs[arg[0]]; ok {
|
m.Target.Conf(arg[0], arg[1])
|
||||||
m.Target.Conf(arg[0], arg[1:]...)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case 4:
|
case 4:
|
||||||
m.Target.Conf(arg[0], arg[1:]...)
|
m.Target.Conf(arg[0], arg[1:]...)
|
||||||
|
@ -601,6 +601,12 @@ func (c *Context) Del(arg ...string) { // {{{
|
|||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
func (c *Context) Cmd(m *Message, key string, arg ...string) string { // {{{
|
func (c *Context) Cmd(m *Message, key string, arg ...string) string { // {{{
|
||||||
|
if m.Meta == nil {
|
||||||
|
m.Meta = make(map[string][]string)
|
||||||
|
}
|
||||||
|
m.Meta["detail"] = []string{key}
|
||||||
|
m.Meta["detail"] = append(m.Meta["detail"], arg...)
|
||||||
|
|
||||||
for s := c; s != nil; s = s.Context {
|
for s := c; s != nil; s = s.Context {
|
||||||
if x, ok := s.Commands[key]; ok {
|
if x, ok := s.Commands[key]; ok {
|
||||||
log.Printf("%s cmd(%s->%s): %v", c.Name, m.Context.Name, m.Target.Name, m.Meta["detail"])
|
log.Printf("%s cmd(%s->%s): %v", c.Name, m.Context.Name, m.Target.Name, m.Meta["detail"])
|
||||||
|
@ -52,9 +52,24 @@ func (web *WEB) Begin(m *ctx.Message) ctx.Server { // {{{
|
|||||||
func (web *WEB) Start(m *ctx.Message) bool { // {{{
|
func (web *WEB) Start(m *ctx.Message) bool { // {{{
|
||||||
|
|
||||||
web.Mux.Handle("/", http.FileServer(http.Dir(web.Conf("directory"))))
|
web.Mux.Handle("/", http.FileServer(http.Dir(web.Conf("directory"))))
|
||||||
s := &http.Server{Addr: web.Conf("address"), Handler: web.Mux}
|
|
||||||
log.Println(web.Name, "listen:", web.Conf("address"))
|
log.Println(web.Name, "listen:", web.Conf("address"))
|
||||||
log.Println(s.ListenAndServe())
|
log.Println(web.Name, "https:", web.Conf("https"))
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if e := recover(); e != nil {
|
||||||
|
log.Println(e)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if web.Conf("https") == "yes" {
|
||||||
|
log.Println(web.Name, "cert:", web.Conf("cert"))
|
||||||
|
log.Println(web.Name, "key:", web.Conf("key"))
|
||||||
|
http.ListenAndServeTLS(web.Conf("address"), web.Conf("cert"), web.Conf("key"), web.Mux)
|
||||||
|
} else {
|
||||||
|
http.ListenAndServe(web.Conf("address"), web.Mux)
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +98,7 @@ var Index = &ctx.Context{Name: "web", Help: "网页服务",
|
|||||||
Configs: map[string]*ctx.Config{
|
Configs: map[string]*ctx.Config{
|
||||||
"address": &ctx.Config{Name: "listen", Value: ":9090", Help: "监听地址"},
|
"address": &ctx.Config{Name: "listen", Value: ":9090", Help: "监听地址"},
|
||||||
"directory": &ctx.Config{Name: "directory", Value: "./", Help: "服务目录"},
|
"directory": &ctx.Config{Name: "directory", Value: "./", Help: "服务目录"},
|
||||||
"who": &ctx.Config{Name: "who", Value: "shylinux", Help: "服务目录"},
|
"https": &ctx.Config{Name: "https", Value: "yes", Help: "开启安全连接"},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
"listen": &ctx.Command{"listen address directory", "设置监听地址和目录", func(c *ctx.Context, m *ctx.Message, key string, arg ...string) string {
|
"listen": &ctx.Command{"listen address directory", "设置监听地址和目录", func(c *ctx.Context, m *ctx.Message, key string, arg ...string) string {
|
||||||
|
@ -3,7 +3,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
_ "context/cli"
|
_ "context/cli"
|
||||||
_ "context/web/mp"
|
_ "context/mdb"
|
||||||
|
// _ "context/web/mp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user