本文整理匯總了TypeScript中express.Response.write方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.write方法的具體用法?TypeScript Response.write怎麽用?TypeScript Response.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Response
的用法示例。
在下文中一共展示了Response.write方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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();
};
示例2: addCharSet
compress.gzip(Buffer.from(geoText), (err: Error, buffer: Buffer) => {
if (is.value(err)) {
view.internalError(res, err);
} else {
res.setHeader(Header.Content.Encoding, Encoding.GZip);
res.setHeader(Header.CacheControl, 'max-age=86400, public'); // seconds
res.setHeader(Header.Content.Type, addCharSet(MimeType.JSON));
res.setHeader(
Header.Content.Disposition,
`attachment; filename=${key}`
);
res.write(buffer);
res.end();
}
});
示例3: writeItemToResponse
export function writeItemToResponse(
res: Response,
item: ViewItem,
cache = true
) {
res.setHeader(Header.Content.Encoding, Encoding.GZip);
if (cache) {
res.setHeader(Header.CacheControl, 'max-age=86400, public'); // seconds
} else {
// force no caching
res.setHeader(Header.CacheControl, 'no-cache');
res.setHeader(Header.Expires, 'Tue, 01 Jan 1980 1:00:00 GMT');
res.setHeader(Header.PRAGMA, 'no-cache');
}
res.setHeader(Header.eTag, item.eTag);
res.setHeader(Header.Content.Type, addCharSet(item.type));
res.write(item.buffer);
res.end();
}
示例4: 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();
}
示例5:
stream.on("data", (doc: Object) => {
res.write(doc, "ascii");
}).on("error", (err: Error) => {
示例6:
stream.on("data", (doc: Object) => {
res.write(doc, "ascii");
complexIO.emit("complex", doc);
}).on("error", (err: Error) => {