[fix] route matching errors, reload matchers

This commit is contained in:
Max 2023-12-13 13:03:06 +08:00
parent 29559c926c
commit 7b11ea82f0
3 changed files with 15 additions and 4 deletions

View file

@ -572,6 +572,8 @@ func PageCreate(process *process.Process) interface{} {
if err != nil {
exception.New(err.Error(), 500).Throw()
}
Reload()
return nil
}
@ -611,6 +613,7 @@ func PageRename(process *process.Process) interface{} {
exception.New(err.Error(), 500).Throw()
}
Reload()
return nil
}
@ -650,6 +653,7 @@ func PageDuplicate(process *process.Process) interface{} {
exception.New(err.Error(), 500).Throw()
}
Reload()
return nil
}
@ -673,6 +677,8 @@ func PageRemove(process *process.Process) interface{} {
if err != nil {
exception.New(err.Error(), 500).Throw()
}
Reload()
return nil
}

View file

@ -125,7 +125,7 @@ func parserPath(c *gin.Context) (string, map[string]string, error) {
parts := strings.Split(strings.TrimSuffix(c.Request.URL.Path, ".sui"), "/")[1:]
if len(parts) < 1 {
return "", nil, fmt.Errorf("no route matchers")
return "", nil, fmt.Errorf("path parts error: %s", strings.Join(parts, "/"))
}
fileParts := []string{string(os.PathSeparator), "public"}
@ -146,7 +146,7 @@ func parserPath(c *gin.Context) (string, map[string]string, error) {
// No matchers
if matchers == nil {
if len(parts) < 1 {
return "", nil, fmt.Errorf("no route matchers")
return "", nil, fmt.Errorf("path parts error: %s", strings.Join(parts, "/"))
}
fileParts = append(fileParts, parts...)
@ -156,7 +156,7 @@ func parserPath(c *gin.Context) (string, map[string]string, error) {
// Match the page parts
for i, part := range parts[1:] {
if len(matchers) < i+1 {
return "", nil, fmt.Errorf("no route matchers")
return "", nil, fmt.Errorf("matchers length error %d < %d", len(matchers), i+1)
}
parent := ""
@ -189,7 +189,7 @@ func parserPath(c *gin.Context) (string, map[string]string, error) {
}
if !matched {
return "", nil, fmt.Errorf("no route matchers")
return "", nil, fmt.Errorf("route does not match")
}
}
return filepath.Join(fileParts...) + ".sui", params, nil

View file

@ -75,6 +75,11 @@ func loadFile(file string, id string) (core.SUI, error) {
return core.SUIs[id], nil
}
// Reload reload the route matchers
func Reload() {
buildRouteMatchers()
}
func buildRouteMatchers() (map[*regexp.Regexp][][]*core.Matcher, map[string][][]*core.Matcher) {
matchers := map[*regexp.Regexp][][]*core.Matcher{}
exactMatchers := map[string][][]*core.Matcher{}