func addAppRouter(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	var appRouter appTypes.AppRouter
	err = ParseInput(r, &appRouter)
	if err != nil {
		return err
	}
	appName := r.URL.Query().Get(":app")
	a, err := getAppFromContext(appName, r)
	if err != nil {
		return err
	}
	_, err = router.Get(appRouter.Name)
	if err != nil {
		if _, isNotFound := err.(*router.ErrRouterNotFound); isNotFound {
			return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
		}
		return err
	}
	allowed := permission.Check(t, permission.PermAppUpdateRouterAdd,
		contextsForApp(&a)...,
	)
	if !allowed {
		return permission.ErrUnauthorized
	}

	p, err := pool.GetPoolByName(a.Pool)
	if err != nil {
		return err
	}
	err = p.ValidateRouters([]appTypes.AppRouter{appRouter})
	if err != nil {
		if err == pool.ErrPoolHasNoRouter {
			return &errors.HTTP{Code: http.StatusBadRequest, Message: err.Error()}
		}
		return err
	}

	evt, err := event.New(&event.Opts{
		Target:     appTarget(appName),
		Kind:       permission.PermAppUpdateRouterAdd,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermAppReadEvents, contextsForApp(&a)...),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	return a.AddRouter(appRouter)
}
func addAppRouter(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	var appRouter appTypes.AppRouter
	err = ParseInput(r, &appRouter)
	if err != nil {
		return err
	}
	appName := r.URL.Query().Get(":app")
	a, err := getAppFromContext(appName, r)
	if err != nil {
		return err
	}
	_, err = router.Get(appRouter.Name)
	if err != nil {
		if _, isNotFound := err.(*router.ErrRouterNotFound); isNotFound {
			return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
		}
		return err
	}
	allowed := permission.Check(t, permission.PermAppUpdateRouterAdd,
		contextsForApp(&a)...,
	)
	if !allowed {
		return permission.ErrUnauthorized
	}

	p, err := pool.GetPoolByName(a.Pool)
	if err != nil {
		return err
	}
	err = p.ValidateRouters([]appTypes.AppRouter{appRouter})
	if err != nil {
		if err == pool.ErrPoolHasNoRouter {
			return &errors.HTTP{Code: http.StatusBadRequest, Message: err.Error()}
		}
		return err
	}

	evt, err := event.New(&event.Opts{
		Target:     appTarget(appName),
		Kind:       permission.PermAppUpdateRouterAdd,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermAppReadEvents, contextsForApp(&a)...),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	return a.AddRouter(appRouter)
}
// title: add app router
// path: /app/{app}/routers
// method: POST
// produce: application/json
// responses:
//   200: OK
//   404: App or router not found
//   400: Invalid request