本文整理汇总了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");
});
示例2: CheckAdmin
CheckAdmin(req.session.username, (isAdmin: boolean) => {
req.session.isAdmin = isAdmin;
if (req.query.url) {
res.redirect(req.query.url);
} else {
res.redirect('/');
}
});
示例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");
});
示例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('/');
}
}
示例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')
}
}
示例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");
}
示例7: authorize
public authorize (req: Request, res: Response, next: NextFunction){
if(!req.isAuthenticated()){
return res.redirect('/');
}
next();
}
示例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);
}
}
示例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("/");
});
});
});
};