• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript restify.Server类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中restify.Server的典型用法代码示例。如果您正苦于以下问题:TypeScript Server类的具体用法?TypeScript Server怎么用?TypeScript Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Server类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: constructor

	constructor(server: Server) {
		server.get('/', serveStatic({
			directory: resolve('./public'),
			file: 'index.html'
		}));

		server.get(/\/__client__\/?.*/, serveStatic({
			directory: resolve('./')
		}));
	}
开发者ID:Ibanheiz,项目名称:tdc-rxjs-demo,代码行数:10,代码来源:Http.ts


示例2: registerHandledRouteTimingMetrics

export function registerHandledRouteTimingMetrics(server: Server, statsDOptions: StatsDOptions) {
    let statsD: StatsD = new StatsD(statsDOptions);
    let metricsKeyBuilder: MetricsKeyBuilder = new MetricsKeyBuilder();
    let logger = new MetricsLogFactory(statsD, metricsKeyBuilder).createLogger();

    server.on('after', (request: Request, response: Response, route: Route, error) => {
        logger(request, response, route);
    });
}
开发者ID:daptiv,项目名称:api-metrics-client,代码行数:9,代码来源:metrics-logger.ts


示例3: registerHandledRouteTimingMetrics

export function registerHandledRouteTimingMetrics(server: Server, statsLogger: DaptivStatsLogger) {
  // A logger and apiStatKeyBuilder should NOT be created here, they should be provided by the caller.
    let apiStatKeyBuilder = new ApiStatKeyBuilder();
    let apiMetricsLogger = new ApiStatsLoggerFactory(statsLogger, apiStatKeyBuilder).createLogger();

    server.on('after', (request: Request, response: Response, route: Route, error) => {
        apiMetricsLogger(request, response, route);
    });
}
开发者ID:daptiv,项目名称:node-daptiv-api-stats-logger,代码行数:9,代码来源:api-stats-logger-factory.ts


示例4: require

import logger from "./logging.config";

import * as restify from "restify";
import {Server} from "restify";

import {registerActionsInExpressApp} from "controllers.ts/Factory";
import {ControllerRunner} from "controllers.ts/ControllerRunner";

let config = require("../../package.json");
let port = process.env.PORT || 3000;
let host = process.env.HOST || "localhost";

logger.info("Setting up restify...");

const server: Server = restify.createServer({
    name: config.name,
    version: config.version
});

server.pre(restify.pre.sanitizePath());

const controllerRunner: ControllerRunner = registerActionsInExpressApp(server, [__dirname + "/../api"]);
controllerRunner.container = {
    get: function (someClass: any): any {
        logger.info("Setting up restify...");
        return kernel.get(someClass.name);
    }
};


server.listen(port, host, () => logger.info(`${server.name}@${config.version} listening at ${host}:${port}`));
开发者ID:barryajones,项目名称:nodejs-rest-mongo-typescript-seed,代码行数:31,代码来源:restify.config.ts


示例5: initialize

 public initialize(server: Server): void {
     server.get('/products', this.listProducts.bind(this));
     server.post('/products', this.addProduct.bind(this));
 }
开发者ID:thinktecture,项目名称:windows-developer-nodejs-typescript,代码行数:4,代码来源:productController.ts


示例6: test

function test(server: Server) {
  server.get('/api/test', (req: Request, res: Response) => {
    res.setCookie('myCookie', 'test' + req.cookies.foo, { path: '/' });
  });
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:5,代码来源:restify-cookies-tests.ts


示例7: resolve

 return new Promise<number>((resolve, reject) => {
   let nextPort    = 0;
   let tryCount    = 0;
   let maxTry      = 10;
   let currentPort = this.port;
   this.server.on('listening', () => {
     resolve(currentPort);
     return;
   });
   this.server.on(
     'error', (e: {code: string}) => {
       switch (e.code) {
         case 'EADDRINUSE':
           tryCount++;
           nextPort = this.port + tryCount;
           this.server.close();
           if (tryCount >= maxTry) {
             reject(e);
             return;
           }
           console.log(`Port in use, retrying on port ${nextPort}...`);
           currentPort = nextPort;
           if (this.hostname) {
             this.server.listen(currentPort, this.hostname);
           } else {
             this.server.listen(currentPort);
           }
           return;
         default:
           reject(e);
           return;
       }
     }
   );
   if (this.hostname) {
     this.server.listen(this.port, this.hostname);
   } else {
     this.server.listen(this.port);
   }
 });
开发者ID:SonicRainBoom,项目名称:lib_router,代码行数:40,代码来源:router.ts


示例8: Error

  addRoute(
    method: string,
    route: string,
    endpoint: RequestHandler
  ): void {
    method = method.toUpperCase();
    switch (method) {
      case 'DELETE':
      case 'DEL':
        this.server.del(route, endpoint);
        break;

      case 'HEAD':
        this.server.head(route, endpoint);
        break;

      case 'PUT':
        this.server.put(route, endpoint);
        break;

      case 'POST':
        this.server.post(route, endpoint);
        break;

      case 'OPTIONS':
        this.server.opts(route, endpoint);
        break;

      case 'GET':
        this.server.get(route, endpoint);
        break;
      default:
        throw new Error(`HTTP-Method ${method} is not implemented!`);
    }
  };
开发者ID:SonicRainBoom,项目名称:lib_router,代码行数:35,代码来源:router.ts


示例9: switch

 'error', (e: {code: string}) => {
   switch (e.code) {
     case 'EADDRINUSE':
       tryCount++;
       nextPort = this.port + tryCount;
       this.server.close();
       if (tryCount >= maxTry) {
         reject(e);
         return;
       }
       console.log(`Port in use, retrying on port ${nextPort}...`);
       currentPort = nextPort;
       if (this.hostname) {
         this.server.listen(currentPort, this.hostname);
       } else {
         this.server.listen(currentPort);
       }
       return;
     default:
       reject(e);
       return;
   }
 }
开发者ID:SonicRainBoom,项目名称:lib_router,代码行数:23,代码来源:router.ts


示例10: enableCORSFix

  /**
   * a crude CORS based on `Qwerios`' comment in
   * https://github.com/mcavage/node-restify/issues/664
   *
   * See issues:
   * https://github.com/mcavage/node-restify/issues/284 (closed)
   * https://github.com/mcavage/node-restify/issues/664 (unresolved)
   *
   * @param additionalHeaders string[]
   * @return void
   */
  enableCORSFix(additionalHeaders: string[] = []): void {
    /*************************************
     Cors
     **************************************/
    this.server.use(restify.CORS());
    let headers = [
      "authorization",
      "withcredentials",
      "x-requested-with",
      "x-forwarded-for",
      "x-real-ip",
      "user-agent",
      "keep-alive",
      "host",
      "accept",
      "connection",
      "upgrade",
      "content-type",
      "dnt",
      "if-modified-since",
      "cache-control"
    ];

    restify.CORS.ALLOW_HEADERS = [
      ...restify.CORS.ALLOW_HEADERS || [],
      ...headers,
      ...additionalHeaders || []
    ];

    // Manually implement the method not allowed handler to fix failing
    // preflights
    this.server.on(
      "MethodNotAllowed",
      (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);
        }
      }
    );
  }
开发者ID:SonicRainBoom,项目名称:lib_router,代码行数:73,代码来源:router.ts



注:本文中的restify.Server类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript restify.plugins类代码示例发布时间:2022-05-25
下一篇:
TypeScript restify.Response类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap