From 67cabfa105b86b30d91ebf556442079ab1a892e5 Mon Sep 17 00:00:00 2001 From: duanhf2012 Date: Tue, 10 Mar 2020 14:07:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Test/config/nodeconfig.json | 4 ++-- Test/logicservice/SubNet1_Service.go | 2 -- Test/main.go | 6 +++--- sysservice/originhttp/httpserverervice.go | 19 ++++++++++++++++--- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Test/config/nodeconfig.json b/Test/config/nodeconfig.json index e745f6d..35a3724 100644 --- a/Test/config/nodeconfig.json +++ b/Test/config/nodeconfig.json @@ -3,7 +3,7 @@ "LogLevel":1, "HttpPort":9400, "WSPort":9401, - "ListenPort":9402, + "ListenPort":9412, "CAFile":[ { "CertFile":"", @@ -23,7 +23,7 @@ "NodeList":[ { "NodeID":1, - "NodeAddr": "127.0.0.1:8081", + "NodeAddr": "127.0.0.1:8181", "LogLevel":1, "HttpPort":7001, "WSPort":7000, diff --git a/Test/logicservice/SubNet1_Service.go b/Test/logicservice/SubNet1_Service.go index 1c93ece..7dc01fe 100644 --- a/Test/logicservice/SubNet1_Service.go +++ b/Test/logicservice/SubNet1_Service.go @@ -52,8 +52,6 @@ type InputData struct { //OnRun ... func (ws *SubNet1_Service) OnRun() bool { - - time.Sleep(time.Second * 10) var cli network.TcpSocketClient cli.Connect("127.0.0.1:9402") diff --git a/Test/main.go b/Test/main.go index d87bbf2..5290f40 100644 --- a/Test/main.go +++ b/Test/main.go @@ -33,15 +33,15 @@ func main() { } //打开Module死循环监控 - node.EnableMonitorModule(time.Second*5) - + node.EnableMonitorModule(time.Minute*5) + originhttp.SetStaticResource(originhttp.METHOD_GET,"/img/","d:/") nodeCfg, _ := cluster.ReadNodeConfig("./config/nodeconfig.json", cluster.GetNodeId()) httpserver := originhttp.NewHttpServerService(nodeCfg.HttpPort) // http服务 for _, ca := range nodeCfg.CAFile { httpserver.SetHttps(ca.CertFile, ca.KeyFile) } - pTcpService := sysservice.NewTcpSocketPbService(":9402") + pTcpService := sysservice.NewTcpSocketPbService(":9412") pTcpService.SetServiceName("ls") /* pTcpService2 := sysservice.NewTcpSocketPbService(":9005") diff --git a/sysservice/originhttp/httpserverervice.go b/sysservice/originhttp/httpserverervice.go index a9a3f63..87d7e1b 100644 --- a/sysservice/originhttp/httpserverervice.go +++ b/sysservice/originhttp/httpserverervice.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "io/ioutil" "net/http" @@ -20,6 +21,7 @@ import ( "github.com/duanhf2012/origin/cluster" "github.com/duanhf2012/origin/network" "github.com/duanhf2012/origin/service" + "github.com/duanhf2012/origin/util/uuid" ) type HttpRedirectData struct { @@ -194,6 +196,17 @@ func (slf *HttpServerService) OnInit() error { } func (slf *ServeHTTPRouterMux) ServeHTTP(w http.ResponseWriter, r *http.Request) { + if origin := r.Header.Get("Origin"); origin != "" { + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") + w.Header().Set("Access-Control-Allow-Headers", + "Action, Module") //有使用自定义头 需要这个,Action, Module是例子 + } + + if r.Method == "OPTIONS" { + return + } + methodRouter, bok := postAliasUrl[r.Method] if bok == false { writeRespone(w, http.StatusNotFound, fmt.Sprint("Can not support method.")) @@ -363,8 +376,8 @@ func staticServer(routerUrl string, routerData RouterStaticResoutceData, w http. } //上传资源 case "POST": - /* // 在这儿处理例外路由接口 + /* var errRet error for _, filter := range slf.httpfiltrateList { ret := filter(r.URL.Path, w, r) @@ -378,7 +391,7 @@ func staticServer(routerUrl string, routerData RouterStaticResoutceData, w http. if errRet != nil { w.Write([]byte(errRet.Error())) return - } + }*/ r.ParseMultipartForm(32 << 20) // max memory is set to 32MB resourceFile, resourceFileHeader, err := r.FormFile("file") if err != nil { @@ -405,7 +418,7 @@ func staticServer(routerUrl string, routerData RouterStaticResoutceData, w http. } defer localfd.Close() io.Copy(localfd, resourceFile) - writeResp(http.StatusOK, upath+fileName)*/ + writeResp(http.StatusOK, upath+"/"+fileName) } }