當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript restify.createServer函數代碼示例

本文整理匯總了TypeScript中restify.createServer函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createServer函數的具體用法?TypeScript createServer怎麽用?TypeScript createServer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了createServer函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: constructor

 constructor(
   opts: RouterOptions
 ) {
   this.server   = opts.server || restify.createServer(opts);
   this.port     = opts.port || 8080;
   this.hostname = opts.hostname || null;
 }
開發者ID:SonicRainBoom,項目名稱:lib_router,代碼行數:7,代碼來源:router.ts

示例2: ShadowsocksManagerService

      stats).then((managedAccessKeyRepository) => {
    const managerService = new ShadowsocksManagerService(managedAccessKeyRepository);
    const certificateFilename = process.env.SB_CERTIFICATE_FILE;
    const privateKeyFilename = process.env.SB_PRIVATE_KEY_FILE;

    // TODO(bemasc): Remove casts once https://github.com/DefinitelyTyped/DefinitelyTyped/pull/15229 lands
    const apiServer = restify.createServer({
      certificate: fs.readFileSync(certificateFilename),
      key: fs.readFileSync(privateKeyFilename)
    });

    // Pre-routing handlers
    apiServer.pre(restify.CORS());

    // All routes handlers
    const apiPrefix = process.env.SB_API_PREFIX ? `/${process.env.SB_API_PREFIX}` : '';
    apiServer.pre(restify.pre.sanitizePath());
    apiServer.use(restify.jsonp());
    apiServer.use(restify.bodyParser());
    setApiHandlers(apiServer, apiPrefix, managerService, stats, serverConfig);

    // TODO(fortuna): Bind to localhost or unix socket to avoid external access.
    apiServer.listen(portNumber, () => {
      logging.info(`Manager listening at ${apiServer.url}${apiPrefix}`);
    });
  });
開發者ID:fang2x,項目名稱:outline-server,代碼行數:26,代碼來源:main.ts

示例3: function

bot.setup().then(() => {

    // Listen to activities sent to the bot
    const server = restify.createServer();
    server.use(restify.plugins.queryParser());
    server.listen(process.env.port || process.env.PORT || 3977, function () {
        console.log('%s listening to %s', server.name, server.url);
    });
    server.post('/api/messages', connector.listen());
});
開發者ID:magencio,項目名稱:UberBotNode_V3,代碼行數:10,代碼來源:app.ts

示例4: serve

/**
 * Start the server and return its URL.
 */
function serve(log: (msg: any) => any): Promise<string> {
  let server = restify.createServer();
  let qp = restify.queryParser({ mapParams: false });

  // Log messages to a file.
  server.get('/log', qp, (req: any, res: any, next: any) => {
    let out = log(JSON.parse(req.query['msg']));
    res.send(out);
    return next();
  });

  // Serve the main HTML and JS files.
  server.get('/', restify.serveStatic({
    // `directory: '.'` appears to be broken:
    // https://github.com/restify/node-restify/issues/549
    directory: '../harness',
    file: 'index.html',
    maxAge: 0,
  }));
  server.get('/client.js', restify.serveStatic({
    directory: './build',
    file: 'client.js',
    maxAge: 0,
  }));

  // Serve the dingus assets.
  server.get(/\/.*/, restify.serveStatic({
    directory: '../dingus',
    default: 'index.html',
    maxAge: 0,
  }));

  // Show errors. This should be a Restify default.
  server.on('uncaughtException', (req: any, res: any, route: any, err: any) => {
    if (err.stack) {
      console.error(err.stack);
    } else {
      console.error(err);
    }
  });

  // More filling in the blanks: log each request as it comes in.
  server.on('after', (req: any, res: any, route: any, err: any) => {
    plog(res.statusCode + " " + req.method + " " + req.url);
  });

  // Start the server.
  let port = 4700;
  let url = "http://localhost:" + port;
  return new Promise((resolve, reject) => {
    server.listen(port, () => {
      resolve(url);
    });
  });
}
開發者ID:Microsoft,項目名稱:staticstaging,代碼行數:58,代碼來源:harness.ts

示例5: constructor

    constructor(name: string) {
        this.router = Restify.createServer({
            name: name
        });

        this.router.on('listening', () => {
            log.debug(`${this.router.name} listening on ${this.router.url}`);
        });

        this.router.use(Restify.acceptParser(this.router.acceptable));
        this.router.use(stripEmptyBearerToken);
        this.router.use(Restify.dateParser());
        this.router.use(Restify.queryParser());
    }
開發者ID:kpreeti096,項目名稱:BotFramework-Emulator,代碼行數:14,代碼來源:restServer.ts

示例6: constructor

        constructor(){

            // Setup Restify Server
            this._server = restify.createServer();
            this._server.listen(process.env.port || process.env.PORT || 3978, () => {
                console.log('%s listening to %s', this._server.name, this._server.url); 
            });
            
            // Create chat bot
            this._botConnector = new builder.ChatConnector({
                appId: process.env.MICROSOFT_APP_ID,
                appPassword: process.env.MICROSOFT_APP_PASSWORD
            });

            this._bot = new builder.UniversalBot(this._botConnector);
            this._server.post('/api/messages', this._botConnector.listen());

            //Init dialogs
            this._dialogsmanager = new BOT.RETAILBOT.DialogsManager();
            this._dialogsmanager.init(this._bot);
        }
開發者ID:DXFrance,項目名稱:botretail,代碼行數:21,代碼來源:retailbot.bot.ts

示例7: serve

/**
 * Start the server and return its URL.
 */
function serve(log: (msg: any) => void): Promise<string> {
  let server = restify.createServer();
  let qp = restify.queryParser({ mapParams: false });

  // Log messages to a file.
  server.get('/log', qp, (req: any, res: any, next: any) => {
    log(JSON.parse(req.query['msg']));
    res.send('done');
    next();
  });

  // Serve the main HTML and JS files.
  server.get('/', restify.serveStatic({
    // `directory: '.'` appears to be broken:
    // https://github.com/restify/node-restify/issues/549
    directory: '../harness',
    file: 'index.html',
  }));
  server.get('/client.js', restify.serveStatic({
    directory: './build',
    file: 'client.js',
  }));

  // Serve the dingus assets.
  server.get(/\/.*/, restify.serveStatic({
    directory: '../dingus',
    default: 'index.html',
  }));

  // Start the server.
  let port = 4700;
  let url = "http://localhost:" + port;
  return new Promise((resolve, reject) => {
    server.listen(port, () => {
      resolve(url);
    });
  });
}
開發者ID:kleopatra999,項目名稱:staticstaging,代碼行數:41,代碼來源:harness.ts

示例8: formatFoo

import * as restify from "restify";
import * as url from "url";
import * as Logger from "bunyan";
import * as http from "http";
import * as stream from "stream";

let server: restify.Server;

server = restify.createServer({
    formatters: {
        'application/foo': function formatFoo(req: restify.Request, res: restify.Response, body: any) {
            if (body instanceof Error)
                return body.stack;

            if (body)
                return body.toString('base64');

            return body;
        }
    }
});

server = restify.createServer({});

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

server.on('someEvent', () => { });

server.use((req: restify.Request, res: restify.Response, next: restify.Next) => { });
server.use([(req: restify.Request, res: restify.Response, next: restify.Next) => { }, (req: restify.Request, res: restify.Response, next: restify.Next) => { }]);
server.use((req: restify.Request, res: restify.Response, next: restify.Next) => { }, (req: restify.Request, res: restify.Response, next: restify.Next) => { });
開發者ID:Jeremy-F,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:restify-tests.ts

示例9:

/// <reference path="../typings/index.d.ts" />

import * as restify from 'restify';

let server = restify.createServer({
  name: 'img-server',
  version: '1.0.0',
});

server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser({
  maxBodySize: 0,
  mapParams: true,
  mapFiles: true,
  overrideParams: true,
  keepExtensions: true,
  multiples: true,
  hash: 'sha1'
}));
server.use(restify.gzipResponse());
server.use(restify.throttle({
  burst: 100,
  rate: 50,
  ip: true,
  overrides: {
    '192.168.1.1': {
      rate: 0,        // unlimited
      burst: 0
    },
    "127.0.0.1": {
開發者ID:zhenhua32,項目名稱:shuoshuo,代碼行數:31,代碼來源:config.ts

示例10: require

import * as restify from 'restify';
import * as fs from 'fs';
import {settings} from './config';
import {logger} from './logger';
import * as auth from './core/auth';

var server = restify.createServer({
    name: settings.name,
    log: logger
});

restify.CORS.ALLOW_HEADERS.push('authorization');
server.use(restify.CORS());
server.pre(restify.pre.sanitizePath());
server.use(restify.acceptParser(server.acceptable));
server.use(restify.bodyParser());
server.use(restify.queryParser());
server.use(restify.authorizationParser());
server.use(restify.fullResponse());
server.use(auth.Auth());

fs.readdirSync(__dirname + '/routes').forEach(function (routeConfig:string) {
    if (routeConfig.substr(-3) === '.js') {
        var route = require(__dirname + '/routes/' + routeConfig);
        route.routes(server);
    }
});

server.listen(settings.port, function () {
    console.log(`INFO: ${settings.name} is running at ${server.url}`);
});
開發者ID:giautm,項目名稱:zeroth,代碼行數:31,代碼來源:app.ts


注:本文中的restify.createServer函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。