Server API

createServer (创建服务器)

restify server 对象是主接口,通过它您将注册传入请求的路由和处理程序。

参数:

  • options Object类型,一个options对象

    • options.name - String类型,服务的名字 (可选, 默认值"restify")

    • options.dtrace -Boolean类型, 启用dTrace支持 (可选, 默认值: false)

    • options.router -Router类型, Router (可选, 默认值: new Router(opts))

    • options.log -Object类型, bunyan 实例. (可选, 默认值: bunyan.createLogger(options.name||"restify"))

    • options.url -String类型,一旦调用listen() , 这将在服务器运行的地方填写。

    • options.certificate -(String | Buffer)类型, 如果要创建HTTPS服务器,请传递一个PEM编码证书和密钥。

    • options.key -(String | Buffer)类型,如果要创建HTTPS服务器,请传递一个PEM编码证书和密钥。

    • options.formatters -Object类型, 用于res.send()的自定义响应格式化程序。

    • options.handleUncaughtExceptions -Boolean类型, 当restify将使用一个域来捕获和响应在它的处理程序堆栈中发生的任何异常异常。bunyan实例,响应头,默认是restify,通过空字符串来设置标题。有显著的负面的性能影响。 (可选, 默认值: false)

    • options.spdy -Object类型, Any options accepted by node-spdy.

    • options.http2 -Object类型,Any options accepted by http2.createSecureServer.

    • options.handleUpgrades -Boolean类型, Hook the upgrade event from the node HTTP server, pushing Connection: Upgrade requests through the regular request handling chain. (可选, 默认值: false)

    • options.onceNext -Boolean类型, Prevents calling next multiple times (可选, 默认值: false)

    • options.strictNext -Boolean类型,Throws error when next() is called more than once, enabled onceNext option (可选, 默认值: false)

    • options.httpsServerOptions -Object类型, Any options accepted by node-https Server. If provided the following restify server options will be ignored: spdy, ca, certificate, key, passphrase, rejectUnauthorized, requestCert and ciphers; however these can all be specified on httpsServerOptions.

    • options.noWriteContinue -Boolean类型, prevents res.writeContinue() in server.on('checkContinue') when proxing (可选, 默认值: false)

    • options.ignoreTrailingSlash -Boolean类型, ignore trailing slash on paths (可选, 默认值: false)

例子:

var restify = require('restify');
var server = restify.createServer();

server.listen(8080, function () {
  console.log('ready on %s', server.url);
});

返回 Server server 类型

Last updated

Was this helpful?