Browse Source

Fix module mount point selection (front-end/back-end)

Vova Tkach 6 years ago
parent
commit
1be6755621
2 changed files with 8 additions and 13 deletions
  1. 1 8
      modules/module_some.go
  2. 7 5
      modules/modules.go

+ 1 - 8
modules/module_some.go

@@ -12,14 +12,7 @@ func (this *Modules) RegisterModule_Some() *Module {
 		WantDB: true,
 		WantDB: true,
 		Mount:  "some",
 		Mount:  "some",
 		Name:   "Some Module",
 		Name:   "Some Module",
-	}, func(wrap *wrapper.Wrapper) {
-		// Front-end
-		fmt.Printf("SOME FrontEnd func call\n")
-		wrap.W.WriteHeader(http.StatusOK)
-		wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
-		wrap.W.Header().Set("Content-Type", "text/html; charset=utf-8")
-		wrap.W.Write([]byte(`SOME FrontEnd func call (` + wrap.CurrModule + `)`))
-	}, func(wrap *wrapper.Wrapper) {
+	}, nil, func(wrap *wrapper.Wrapper) {
 		// Back-end
 		// Back-end
 		fmt.Printf("SOME BackEnd func call\n")
 		fmt.Printf("SOME BackEnd func call\n")
 		wrap.W.WriteHeader(http.StatusOK)
 		wrap.W.WriteHeader(http.StatusOK)

+ 7 - 5
modules/modules.go

@@ -79,15 +79,17 @@ func (this *Modules) newAction(info AInfo, af func(wrap *wrapper.Wrapper)) *Acti
 	return &Action{Info: info, Act: af}
 	return &Action{Info: info, Act: af}
 }
 }
 
 
-func (this *Modules) getCurrentModule(wrap *wrapper.Wrapper) (*Module, string) {
+func (this *Modules) getCurrentModule(wrap *wrapper.Wrapper, backend bool) (*Module, string) {
 	var mod *Module = nil
 	var mod *Module = nil
 	var modCurr string = ""
 	var modCurr string = ""
 
 
 	// Some module
 	// Some module
 	if len(wrap.UrlArgs) >= 1 {
 	if len(wrap.UrlArgs) >= 1 {
 		if m, ok := this.mods[wrap.UrlArgs[0]]; ok {
 		if m, ok := this.mods[wrap.UrlArgs[0]]; ok {
-			mod = m
-			modCurr = wrap.UrlArgs[0]
+			if (!backend && m.Front != nil) || (backend && m.Back != nil) {
+				mod = m
+				modCurr = wrap.UrlArgs[0]
+			}
 		}
 		}
 	}
 	}
 
 
@@ -147,7 +149,7 @@ func (this *Modules) XXXActionFire(wrap *wrapper.Wrapper) bool {
 }
 }
 
 
 func (this *Modules) XXXFrontEnd(wrap *wrapper.Wrapper) bool {
 func (this *Modules) XXXFrontEnd(wrap *wrapper.Wrapper) bool {
-	mod, cm := this.getCurrentModule(wrap)
+	mod, cm := this.getCurrentModule(wrap, false)
 	if mod != nil {
 	if mod != nil {
 		wrap.CurrModule = cm
 		wrap.CurrModule = cm
 		if mod.Front != nil {
 		if mod.Front != nil {
@@ -167,7 +169,7 @@ func (this *Modules) XXXFrontEnd(wrap *wrapper.Wrapper) bool {
 }
 }
 
 
 func (this *Modules) XXXBackEnd(wrap *wrapper.Wrapper) bool {
 func (this *Modules) XXXBackEnd(wrap *wrapper.Wrapper) bool {
-	mod, cm := this.getCurrentModule(wrap)
+	mod, cm := this.getCurrentModule(wrap, true)
 	if mod != nil {
 	if mod != nil {
 		wrap.CurrModule = cm
 		wrap.CurrModule = cm
 		if mod.Back != nil {
 		if mod.Back != nil {