本文整理匯總了TypeScript中express.Response.set方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.set方法的具體用法?TypeScript Response.set怎麽用?TypeScript Response.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Response
的用法示例。
在下文中一共展示了Response.set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: async
async (req: Request, res: Response): Promise<void> => {
const templateData: TemplateDataInterface = getTemplateData(page);
if (!page.content) {
return renderError(res, templateData);
}
// Blog Page render
if (page.action.startsWith("/blog")) {
const slug: string = req.params.id;
const post = page.action !== "/blog"
? await getPost(posts, slug)
: null;
if (post) {
if (post.error) {
return renderError(res, templateData);
}
if (post.redirect) {
return res.status(301)
.redirect(`https://archive.drublic.de/blog/${post.redirect}`);
}
}
return res.render(page.content, {
...templateData,
...getPostsData(),
post,
});
}
if (page.action === "/") {
const data = {
...templateData,
...getPostsData(),
...getWdPostsData(),
};
return res
.set({
"Cache-Control": `max-age=${60 * 60 * 24}`,
})
.render(page.content, data);
}
// Normal page render
try {
return res
.set({
"Cache-Control": `max-age=${60 * 60 * 24}`,
})
.render(page.content, templateData);
} catch (error) {
return renderError(res, templateData);
}
},
示例2: signIn
signIn(res: Response, user: User): TokenUserDto {
const token = this.createToken(user);
res.set('Authorization', token.accessToken);
res.set('expiresIn', '' + token.expiresIn);
return {
id: user.id,
name: user.name,
email: user.email,
role: user.role,
clubId: user.clubId
}
}
示例3: setODataVersion
/**
* Sets the OData-Version response header. This must be delivered by an OData-Server
* @param res
* @private
*/
setODataVersion(res:Response, version: string) {
// default for OData version is 4.0
if(!version) {
version = "4.0"
}
if(version === "4.0") {
res.set('OData-Version', version);
} else if(version === "2.0") {
res.set('dataserviceversion', version);
}
}
示例4: function
return function(req: Request, res: Response): void {
const cdn = 'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.13.1'
res.set('content-type', 'text/html')
res.send(`
<html>
<head>
<title>${spec.info.title} API Documentation</title>
<link rel="stylesheet" type="text/css" href="${cdn}/swagger-ui.css">
</head>
<body>
<div id="swagger-ui"></div>
<script src="${cdn}/swagger-ui-bundle.js"></script>
<script src="${cdn}/swagger-ui-standalone-preset.js"></script>
<script>
window.onload = function () {
window.ui = SwaggerUIBundle({
url: new URL("${swaggerPath}", window.location.href).href,
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
}
</script>
`)
res.end()
}
示例5: next
.then(session => {
// console.log('new session created', session.sessionData);
let token = JWT.sign({sessionId: session.sessionId});
res.set('X-Auth-Token', token);
req.session = session;
next();
});
示例6: renderSitemap
export function renderSitemap(req: Request, res: Response) {
var cfg: ConfigService = ConfigService.getInstance();
var rs: RoutingService = RoutingService.getInstance();
res.set('Content-Type', 'text/xml');
res.status(200).render('sitemap', {'routes': rs.flatRoutes, 'siteRoot': cfg.siteRoot});
}
示例7: newSession
.then(session => {
if (!session) {
// session has been expired
return newSession();
}
// console.log('session verified', session.sessionData);
res.set('X-Auth-Token', token);
req.session = session;
next();
});
示例8: catch
app.post("/auth", (req: Request, res: Response, next: NextFunction) => {
const token = req.body.token;
try {
jwt.verify(token, Key.PUBLIC, {algorithms: ["RS256"]});
} catch (e) {
next({message: "@@@@ トークン不正 " + e.message });
return;
}
res.set("Content-Type", "aplication/json; charset=utf-8")
.json({ message: "@@@@ トークン正常"});
});
示例9: function
router.post('/login', function(req: Request, res: Response, next: Function) {
let username = req.body.username;
let password = req.body.password;
let user = UserService.findById(username);
if(user && (password === user.password)) {
res.set('jwt', jsonwebtoken.sign({sub: user.id}, 'secret'));
res.sendStatus(200);
} else {
res.sendStatus(403);
}
});
示例10: return
return (req: Request, res: Response, next: RequestHandler) => {
res.set('OData-Version', '4.0');
var data = this.document(format)
if (!data['@odata.context']) {
var url = req.protocol + '://' + req.get('host') + req.originalUrl.split("?").shift();
if(url.slice(-1) !== '/') url += '/'
data['@odata.context'] = url + '$metadata';
}
res.json(data);
};
示例11: async
async (req: Request, res: Response): Promise<void> => {
const templateData = getTemplateData({
title: "",
action: "/",
});
const posts: any[] = await getPosts();
return res
.set({
"Content-Type": "application/xml; charset=utf-8",
"Cache-Control": `max-age=${60 * 60 * 24}`,
})
.render("feed", {
layout: false,
...templateData,
posts,
});
},
示例12: postFeed
export function postFeed(req: Request, res: Response) {
if (!blog.postInfoLoaded) {
if (rssRetries >= MAX_RSS_RETRIES) {
log.error(`Unable to load blog after ${MAX_RSS_RETRIES} tries`);
view.notFound(req, res);
// reset tries so page can be refreshed
rssRetries = 0;
} else {
rssRetries++;
log.error(
`Blog posts not ready when creating RSS feed — attempt ${rssRetries}`
);
setTimeout(() => {
postFeed(req, res);
}, 1000);
}
return;
}
res.set(Header.Content.Type, MimeType.XML);
res.write(render(blog));
res.end();
}
示例13:
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
// レスポンス
res.set("Content-Type", "application/json; charset=utf-8").json(err);
});
示例14: next
app.use(function (req: IRequest, res: Response, next: NextFunction): void {
res.set(corsHeaders);
next();
});
示例15: function
app.options('*', function (req: IRequest, res: Response, next: NextFunction): void {
res.set(corsHeaders).end();
});