本文整理匯總了TypeScript中restify.Response.header方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.header方法的具體用法?TypeScript Response.header怎麽用?TypeScript Response.header使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類restify.Response
的用法示例。
在下文中一共展示了Response.header方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
(request: Request, response: Response) => {
if (request.method.toUpperCase() !== "OPTIONS") {
response.send(new restify.MethodNotAllowedError());
return;
} else {
// Send the CORS headers
//
response.header("Access-Control-Allow-Credentials", true);
response.header(
"Access-Control-Allow-Headers",
restify.CORS.ALLOW_HEADERS.join(", ")
);
response.header(
"Access-Control-Allow-Methods",
"GET, HEAD, POST, PUT, DELETE, OPTIONS"
);
response.header(
"Access-Control-Allow-Origin",
request.headers.origin
);
response.header("Access-Control-Max-Age", 0);
response.header("Content-type", "text/plain charset=UTF-8");
response.header("Content-length", 0);
response.send(204);
}
}
示例2: return
return (request: Request, response: Response, route: Route) => {
let latency = response.header('Response-Time');
if (typeof (latency) !== 'number') {
latency = Date.now() - request.time();
}
if (!latency) {
return;
}
let routeSpec: RouteSpec = route && route.spec;
let key: string = this.metricsKeyBuilder.fromRouteSpecAndStatus(routeSpec, response.statusCode);
this.statsD.timing(key, latency);
};