本文整理汇总了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;未经允许,请勿转载。 |
请发表评论