本文整理匯總了TypeScript中express.Response.end方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.end方法的具體用法?TypeScript Response.end怎麽用?TypeScript Response.end使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Response
的用法示例。
在下文中一共展示了Response.end方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
proxied.on("error", (err: any) => {
if (err.code === "ETIMEDOUT" || err.code === "ESOCKETTIMEDOUT") {
res.statusCode = 504;
return res.end("Timed out waiting for function to respond.");
}
res.statusCode = 500;
res.end(`An internal error occurred while proxying for ${rewriteIdentifier}`);
});
示例2: 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()
}
示例3: Date
res.end = (chunk?: any, encoding?: string | Function): void => {
res.end = end;
res.end(chunk, (encoding as string));
meta.res = {
statusCode: res.statusCode,
responseTime: (new Date() as any) - res.locals.startTime,
};
if (resLog.headers) {
// there are 2 headers that will not appear here:
// 1. Date: "server date"
// 2. Connection: "keep-alive"
// there is an npm package that extracts these 2 headers too but it doesn't make sens to use it just for that
// npm: https://github.com/watson/http-headers
meta.res.headers = (res as any)._headers;
}
if (resLog.body && chunk) {
const contentType = res.getHeader("content-type");
const isJson = typeof contentType === "string" && contentType.indexOf("json") >= 0;
meta.res.body = bodyToString(chunk, isJson);
}
logger.info("http-logger", meta);
};
示例4:
Subject.findOneAndUpdate({code: code}, {$pull: {"tasks.requirements": {_id: req.params.id}}}).exec((err) => {
if (!err) {
res.end();
} else {
res.json(err);
}
});
示例5:
user.save((err) => {
if (!err) {
res.end();
} else {
res.status(400).json(err);
}
});
示例6: function
var serverError = function (response: Response, message: string, user?: User) {
logger.error(message, user);
response.type('application/json; charset=utf-8');
response.writeHead(500);
response.write('{"error": "' + message + '"}');
response.end();
};