new: add config redirect
This commit is contained in:
parent
12e3b0c2d4
commit
f203d5cc51
2
main.go
2
main.go
@ -50,7 +50,7 @@ func main(){
|
||||
app.Get("/wiki/:id", routes.WikiRoute)
|
||||
|
||||
app.Get("/hub", routes.ConfigsRoute)
|
||||
app.Get("/hub/:id", routes.ConfigRoute)
|
||||
app.Get("/hub/:name", routes.ConfigRoute)
|
||||
|
||||
app.Get("*", func(c *fiber.Ctx) error {
|
||||
return lib.RenderError(c, 404)
|
||||
|
@ -122,5 +122,19 @@ func ConfigsRoute(c *fiber.Ctx) error{
|
||||
}
|
||||
|
||||
func ConfigRoute(c *fiber.Ctx) error{
|
||||
return c.Redirect("/configs")
|
||||
name := c.Params("name")
|
||||
|
||||
configs, err := GetConfigs()
|
||||
if err != nil {
|
||||
log.Printf("GetConfigs failed: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
|
||||
for _, cur := range configs {
|
||||
if cur.Name == name {
|
||||
return c.Redirect(cur.Redirect)
|
||||
}
|
||||
}
|
||||
|
||||
return lib.RenderError(c, 404)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user