当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Response.redirect方法代码示例

本文整理汇总了TypeScript中express.Response.redirect方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Response.redirect方法的具体用法?TypeScript Response.redirect怎么用?TypeScript Response.redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在express.Response的用法示例。


在下文中一共展示了Response.redirect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

 transporter.sendMail(mailOptions, (err) => {
   if (err) {
     req.flash("errors", { msg: err.message });
     return res.redirect("/contact");
   }
   req.flash("success", { msg: "Email has been sent successfully!" });
   res.redirect("/contact");
 });
开发者ID:20B2,项目名称:TypeScript-Node-Starter,代码行数:8,代码来源:contact.ts

示例2: CheckAdmin

      CheckAdmin(req.session.username, (isAdmin: boolean) => {
        req.session.isAdmin = isAdmin;

        if (req.query.url) {
          res.redirect(req.query.url);
        } else {
          res.redirect('/');
        }
      });
开发者ID:dasahcc,项目名称:helix,代码行数:9,代码来源:user.ts

示例3: next

 user.save((err: WriteError) => {
   if (err) {
     if (err.code === 11000) {
       req.flash("errors", { msg: "The email address you have entered is already associated with an account." });
       return res.redirect("/account");
     }
     return next(err);
   }
   req.flash("success", { msg: "Profile information has been updated." });
   res.redirect("/account");
 });
开发者ID:babula38,项目名称:TypeScript-Node-Starter,代码行数:11,代码来源:user.ts

示例4: authorize

  protected authorize(req: Request, res: Response) {

    // you can rewrite this function to support your own authorization logic
    // by default, doing nothing but redirection

    if (req.query.url) {
      res.redirect(req.query.url);
    } else {
      res.redirect('/');
    }
  }
开发者ID:apache,项目名称:helix,代码行数:11,代码来源:user.ts

示例5: catch

export const link = (req: Request, res: Response) => {
  log.info('redirect.call', Object.assign({}, req.params, req.query, req.body))
  if (!req.query.url) {
    log.error('redirect.params.url.invalid', req.query)
    res.redirect('/404')
    return
  }
  try {
    res.redirect(req.query.url)
  } catch (error) {
    log.error('redirect.catch', req.query)
    res.redirect('/404')
  }
}
开发者ID:linkFly6,项目名称:Said,代码行数:14,代码来源:home.ts

示例6: remove

async function remove(req: Request, res: Response): Promise<void> {
    if (!req.params.id) {
        DKYSession.raiseMessage(req.session, "danger", "Post not found.");
        // Redirect back to list.
        res.redirect("/post");
        return;
    }

    // Remove post.
    await modelPost.removePost(req.params.id);

    DKYSession.raiseMessage(req.session, "success", "Post deleted successfully.");
    // Redirect back to list.
    res.redirect("/post");
}
开发者ID:nicholas-robson,项目名称:dkydev_webapp,代码行数:15,代码来源:post.ts

示例7: authorize

 public authorize (req: Request, res: Response, next: NextFunction){
     
     if(!req.isAuthenticated()){
         return res.redirect('/');
     }
     next();
 }
开发者ID:Devaio,项目名称:Starter-code,代码行数:7,代码来源:middleware.ts

示例8: postNew

  public async postNew(req: Request, res: Response, next: any) {
    try {
      const currentSeason = await this.sql.getSelectedSeason(undefined);
      if (currentSeason === undefined) {
        res.status(404);
        return;
      }

      const startDate = currentSeason.getStartDate();
      if (startDate <= new Date()) {
        res.status(403).contentType("text/plain").send("Season has already begun.");
        return;
      }

      const teams = currentSeason.teams.filter((t) => t.id.toString() === req.body.teamId);
      if (teams.length === 0) {
        res.status(404).contentType("text/plain").send("Team not found.");
        return;
      }
      const selectedTeam = teams[0];

      const newPlayer = Player.fromPostBody(req.body, currentSeason.movies);
      const savedPlayer = await this.sql.addPlayerToTeam(newPlayer, selectedTeam);

      if (req.body.email) {
        const envelope = this.emailSender.getEmail(req.body.email, savedPlayer, currentSeason.name);
        await this.emailSender.sendMail(envelope);
      }

      res.redirect(`/new?team=${selectedTeam.slug}&thanks=1`);
    } catch (e) {
      next(e);
    }
  }
开发者ID:snickroger,项目名称:FantasyMovieLeague,代码行数:34,代码来源:newController.ts

示例9: User

export let postSignup = (req: Request, res: Response, next: NextFunction) => {
  req.assert("email", "Email is not valid").isEmail();
  req.assert("password", "Password must be at least 4 characters long").len({ min: 4 });
  req.assert("confirmPassword", "Passwords do not match").equals(req.body.password);
  req.sanitize("email").normalizeEmail({ gmail_remove_dots: false });

  const errors = req.validationErrors();

  if (errors) {
    req.flash("errors", errors);
    return res.redirect("/signup");
  }

  const user = new User({
    email: req.body.email,
    password: req.body.password
  });

  User.findOne({ email: req.body.email }, (err, existingUser) => {
    if (err) { return next(err); }
    if (existingUser) {
      req.flash("errors", { msg: "Account with that email address already exists." });
      return res.redirect("/signup");
    }
    user.save((err) => {
      if (err) { return next(err); }
      req.logIn(user, (err) => {
        if (err) {
          return next(err);
        }
        res.redirect("/");
      });
    });
  });
};
开发者ID:babula38,项目名称:TypeScript-Node-Starter,代码行数:35,代码来源:user.ts


注:本文中的express.Response.redirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。