mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
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
|
||||
|
||||
~mp
|
||||
listen :9090 ./
|
||||
~web
|
||||
source etc/mp.sh
|
||||
~mdb
|
||||
& start
|
||||
|
||||
|
@ -478,9 +478,7 @@ var Index = &ctx.Context{Name: "cli", Help: "本地控制", // {{{
|
||||
delete(m.Target.Configs, arg[1])
|
||||
}
|
||||
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:
|
||||
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 { // {{{
|
||||
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 {
|
||||
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"])
|
||||
|
@ -52,9 +52,24 @@ func (web *WEB) Begin(m *ctx.Message) ctx.Server { // {{{
|
||||
func (web *WEB) Start(m *ctx.Message) bool { // {{{
|
||||
|
||||
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(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
|
||||
}
|
||||
|
||||
@ -83,7 +98,7 @@ var Index = &ctx.Context{Name: "web", Help: "网页服务",
|
||||
Configs: map[string]*ctx.Config{
|
||||
"address": &ctx.Config{Name: "listen", Value: ":9090", 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{
|
||||
"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 (
|
||||
"context"
|
||||
_ "context/cli"
|
||||
_ "context/web/mp"
|
||||
_ "context/mdb"
|
||||
// _ "context/web/mp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user