本文整理匯總了TypeScript中express.Response.render方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.render方法的具體用法?TypeScript Response.render怎麽用?TypeScript Response.render使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Response
的用法示例。
在下文中一共展示了Response.render方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: create
export function create (req: Request, res: Response) {
let generated = false;
let key = randomString(50);
let secret = null;
if (!req.body.secret) {
console.log('generate');
generated = true;
secret = randomString(20);
} else {
console.log('create');
secret = req.body.secret;
}
r.store(key, secret);
let secret_url = req.headers['host'] + '/get/' + key;
if (generated) {
console.log('generated');
res.render('generate', { generated: secret, secret_url: secret_url});
} else {
console.log('created');
res.render('created', { url: secret_url });
}
}
示例2:
}), req.body["password"], (err: any, account: any) => {
if (err) {
return res.render("auth", { title: "Auth Error " + err });
}
res.render("auth", { title: "Signup Success" });
});
示例3: list
list(req: Request, res: Response) {
if (process.env.NODE_ENV === 'testing') {
res.render('ng-unit-tests');
} else {
res.render('index');
}
}
示例4:
export const about = (req: Request, res: Response) => {
if (res.locals.device === DEVICE.MOBILE) {
res.render('home/about-mobile', {
title: '關於聽說 - 世界很大,風住過這裏',
bodyClassName: 'body-home-about'
})
} else {
res.render('home/about', {
pageIndex: 3,
title: '關於聽說 - 世界很大,風住過這裏',
})
}
}
示例5: internalError
/**
* Render status `500` page.
*/
function internalError(res: Response, err?: Error): void {
if (is.value(err)) {
log.error(err);
}
res.statusCode = HttpStatus.InternalError;
res.render(Page.InternalError, { title: 'Oops', config });
}
示例6:
app.use(function(err: HttpError, req: Request, res: Response) {
res.status(err.status || 500);
res.render("error", {
error: {},
message: err.message,
});
});
示例7: tags
function tags(req: Request, res: Response) {
let slug = tagParam(req);
const list = blog.tags;
const keys = Array.from(list.keys());
const tags: { [key: string]: { [key: string]: string } } = {};
if (is.empty(slug)) {
// select a random tag
slug = keys[Math.floor(Math.random() * keys.length + 1)];
}
// group tags by first letter (character)
for (const c of alphabet) {
tags[c] = {};
}
for (const [key, value] of list.entries()) {
// key is sometimes a number
const c = (key.toString()).substr(0, 1).toLowerCase();
if (alphabet.indexOf(c) >= 0) {
// ignore tags that don't start with a letter of the alphabet
tags[c][key] = value;
}
}
res.render(Page.PhotoTag, {
tags,
selected: slug,
alphabet,
title: keys.length + ' Photo Tags',
config
});
}
示例8: index
public async index(req: Request, res: Response, next: any) {
try {
const seasons = await this.sql.getAllSeasonsForMenu();
const selectedSeason = await this.sql.getSelectedSeason(req.query.season);
if (selectedSeason === undefined) {
// season does not exist
res.status(404).send("Season not found");
return;
}
const startDate = selectedSeason.getStartDate();
if (startDate > new Date() && req.query.skip !== "1") {
res.redirect(307, "/new");
}
const teams = selectedSeason.teams.map((t) => ({ id: t.slug, name: t.name }));
res.render("home/index_noteam", {
title: selectedSeason.pageTitle,
teams,
slug: selectedSeason.slug,
seasons,
});
} catch (e) {
next(e);
}
}
示例9:
app.use(function (req: IRequest, res: Response, next: NextFunction): void {
res.status(err.status || 500);
res.render('error', {
error: {},
message: err.message
});
});
示例10: get
public async get(req: Request, res: Response, next: any) {
try {
const movieId = parseInt(req.params.id, 10);
const teamId = parseInt(req.query.team, 10);
const team = await this.sql.getTeam(teamId);
if (team === undefined) {
res.status(404).send("Team not found");
return;
}
const movie = await this.sql.getMovie(movieId, team);
if (movie === undefined) {
res.status(404).send("Movie not found");
return;
}
const movieEarnings = MovieEarnings.getMovieEarningsDisplay(movie, team.players);
const totalShares = movieEarnings.totalShares();
const totalEarned = movieEarnings.totalEarnedDisp();
const chart = MovieEarnings.getMovieEarningsChartData(movie);
res.render("movie/get", {
chart,
movie,
movieEarnings,
team,
title: `${movie.name} | Earnings`,
totalEarned,
totalShares,
});
} catch (e) {
next(e);
}
}
示例11: async
get: async (req: Request, res: Response) => {
const users = await getClient().many(query);
const groupedUsers = _.groupBy(users, u => u.role);
res.render("users", {users: groupedUsers});
}
示例12:
let handler = (err: Error, req: Request, res: Response, next: Function, includeStackTrace: boolean) => {
res.status(res.statusCode || 500);
res.render('error', {
message: err.message,
error: includeStackTrace ? err : {}
});
};
示例13: blogMap
/**
* @see https://www.mapbox.com/mapbox-gl-js/example/cluster/
*/
function blogMap(_req: Request, res: Response) {
res.render(Page.Mapbox, {
layout: Layout.None,
title: config.site.title + ' Map',
config
});
}
示例14:
app.use(function(err: any, req: Request, res: Response, next: Function): void {
res.status(err.status || 500);
res.render("error", {
message: err.message,
error: err,
});
});
示例15:
app.use(function(err: any, req: Request, res: Response, next: Function) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});