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

TypeScript https.createServer函数代码示例

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

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



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

示例1:

        server: (function () {
            if (options.get('scheme') === 'https') {
                const pfxPath = options.getIn(['https', 'pfx']);

                if (pfxPath) {
                    return https.createServer(getPFX(pfxPath), app);
                }

                return https.createServer(getKeyAndCert(options), app);
            }
            return http.createServer(app);
        })(),
开发者ID:b-cuts,项目名称:browser-sync-core,代码行数:12,代码来源:server.ts


示例2: _startAuthenticationServer

 _startAuthenticationServer():Promise {
   var result = deferred();
   
   var port = config.controlChannelPort + 1;
   var serverOptions = {
     key: keys.privateKey,
     cert: keys.certificate
   };
   https.createServer(serverOptions, (req, res) => {
     var path = this._pathForRequest(req);
     console.log("Path:", path);
     if (path.indexOf('authenticate') === 0) {
       return this._authenticate(req, res);
     }
   }).listen(port, function(err) {
     if (err) {
       result.reject('Unable to start control channel server: ' +  err);
     } else {
       console.log('Listening for authentication requests on port', port);
       result.resolve();
     }
   });
   
   return result.promise;
 }
开发者ID:PowerOlive,项目名称:lantern-node,代码行数:25,代码来源:ControlChannel.ts


示例3: start

export function start(
  port,
  networkInterface,
  ssl,
  _listener,
  onConnection?
): void {
  listener = _listener;

  if (ssl) {
    const options = {
      key: fs.readFileSync(ssl.key),
      cert: fs.readFileSync(ssl.cert),
      ca: null
    };

    try {
      // Use intermediate certificates if available
      options.ca = fs
        .readFileSync(ssl.ca)
        .toString()
        .match(/-+BEGIN CERTIFICATE-+[0-9a-zA-Z+\-/=\s]+?-+END CERTIFICATE-+/g);
    } catch (error) {
      // No intermediate certificate
    }
    server = https.createServer(options, listener);
    if (onConnection != null) server.on("secureConnection", onConnection);
  } else {
    server = http.createServer(listener);
    if (onConnection != null) server.on("connection", onConnection);
  }

  server.listen(port, networkInterface);
}
开发者ID:zaidka,项目名称:genieacs,代码行数:34,代码来源:server.ts


示例4: startServer

function startServer(webServerConfig: IWebServerConfig, app: core.Express, done:(secure: boolean, host:string, port:number) => void, errorCallback?:(err:any) => void ) : void {
	let server: net.Server = null;
	let wsConfig: IHTTPServerConfig = null;
	if (webServerConfig.https) {
		wsConfig = webServerConfig.https;
		let httpsConfig = webServerConfig.https;
		let sslConfig = httpsConfig.ssl;
		let private_key_file = sslConfig.private_key_file;
		let certificate_file = sslConfig.certificate_file;
		let ca_files = sslConfig.ca_files;
		let privateKey  = fs.readFileSync(private_key_file, 'utf8');
		let certificate = fs.readFileSync(certificate_file, 'utf8');
		let credentials:https.ServerOptions = {key: privateKey, cert: certificate};
		if (ca_files && ca_files.length > 0) {
			let ca:string[] = [];
			for (let i in ca_files)
				ca.push(fs.readFileSync(ca_files[i], 'utf8'));
			credentials.ca = ca;
		}
		server = https.createServer(credentials, app);
	} else {
		wsConfig = webServerConfig.http;
		server = http.createServer(app);
	}
	let port = (wsConfig.port ? wsConfig.port : (webServerConfig.https ? 443 : 80));
	let host = (wsConfig.host ? wsConfig.host : "0.0.0.0");	
	server.on('error', (err:any) => {
		if (typeof errorCallback === 'function') errorCallback(err);
	});
	server.listen(port, host, () => {
		let host = server.address().address;
		let port = server.address().port;
		if (typeof done === 'function') done((webServerConfig.https ? true : false), host, port);
	});
}
开发者ID:wchang28,项目名称:express-web-server,代码行数:35,代码来源:index.ts


示例5: createHttpServer

export async function createHttpServer(devServerConfig: d.DevServerConfig, fs: d.FileSystem, destroys: d.DevServerDestroy[]) {
  // figure out the port to be listening on
  // by figuring out the first one available
  devServerConfig.port = await findClosestOpenPort(devServerConfig.address, devServerConfig.port);

  // create our request handler
  const reqHandler = createRequestHandler(devServerConfig, fs);

  let server: http.Server;

  if (devServerConfig.protocol === 'https') {
    // https server
    server = https.createServer(await getSSL(), reqHandler) as any;

  } else {
    // http server
    server = http.createServer(reqHandler);
  }

  destroys.push(() => {
    // close down the serve on destroy
    server.close();
    server = null;
  });

  return server;
}
开发者ID:franktopel,项目名称:stencil,代码行数:27,代码来源:server-http.ts


示例6: _startControlChannelServer

 _startControlChannelServer():Promise {
   var result = deferred();
   
   var port = config.controlChannelPort;
   var serverOptions = {
     key: keys.privateKey,
     cert: keys.certificate,
     ca: [keys.certificate],
     requestCert: true,
     rejectUnauthorized: true
   };
   https.createServer(serverOptions, (req, res) => {
     var path = this._pathForRequest(req);
     console.log(req.connection.getPeerCertificate());
     console.log(req.secure);
     console.log(req.client.authorized);
   }).listen(port, function(err) {
     if (err) {
       result.reject('Unable to start control channel server: ' +  err);
     } else {
       console.log('Listening for control channel traffic on port', port);
       result.resolve();
     }
   });
   
   return result.promise;
 }
开发者ID:PowerOlive,项目名称:lantern-node,代码行数:27,代码来源:ControlChannel.ts


示例7: createSimpleServer

function createSimpleServer({ port = 8000 }) {
    const server = createServer({ key: privateKey, cert: certificate });
    server.addListener('request', request);
    server.listen(port);
    console.log(`Listen port ${port}, for simple server`);
    console.log(`https://${ip}:${port}`);
}
开发者ID:wavesplatform,项目名称:WavesGUI,代码行数:7,代码来源:server.ts


示例8: run

  async run(inputs: CommandLineInputs, options: CommandLineOptions) {
    const [ url ] = inputs;
    const { host, port, ssl } = options;

    const protocol = ssl ? 'https' : 'http';
    const projectType = options['project-type'];
    const name = options['app-name'];
    const version = options['app-version'];

    const app = express();

    app.use('/', express.static(WWW_DIRECTORY));

    app.get('/api/app', (req, res) => {
      res.json({ url, name, version, projectType });
    });

    const server = ssl ? https.createServer(await this.collectSecureContextOptions(options), app) : http.createServer(app);
    server.listen({ port, host });

    const labUrl = `${protocol}://${host}:${port}`;

    server.on('listening', () => {
      process.stdout.write(
        'Ionic Lab running!\n' +
        `Lab: ${chalk.bold(labUrl)}\n` +
        `App: ${chalk.bold(url)}\n`
      );
    });
  }
开发者ID:driftyco,项目名称:ionic-cli,代码行数:30,代码来源:index.ts


示例9: before

  before((done) => {
    const options = {
      key: fs.readFileSync(path.join(certPath, 'server.key')),
      cert: fs.readFileSync(path.join(certPath, 'server.pem')),
      ca: [
        fs.readFileSync(path.join(certPath, 'rootCA.pem')),
        fs.readFileSync(path.join(certPath, 'intermediateCA.pem'))
      ],
      requestCert: true,
      rejectUnauthorized: false
    }

    server = https.createServer(options, (req, res) => {
      if ((req as any).client.authorized) {
        res.writeHead(200)
        res.end('<title>authorized</title>')
      } else {
        res.writeHead(401)
        res.end('<title>denied</title>')
      }
    })

    server.listen(0, '127.0.0.1', () => {
      const port = (server.address() as net.AddressInfo).port
      secureUrl = `https://127.0.0.1:${port}`
      done()
    })
  })
开发者ID:malept,项目名称:electron,代码行数:28,代码来源:api-app-spec.ts


示例10: co

  return co(function *createHttpsServer() {
    const privateKeyPromise = fs.readFileAsync(keypath, 'utf8');
    const certificatePromise = fs.readFileAsync(crtpath, 'utf8');

    const [key, cert] = yield Promise.all([privateKeyPromise, certificatePromise]);

    return https.createServer({ secureOptions: SSL_OP_NO_TLSv1, key, cert }, app);
  }).call(this);
开发者ID:BitGo,项目名称:BitGoJS,代码行数:8,代码来源:expressApp.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript https.get函数代码示例发布时间:2022-05-25
下一篇:
TypeScript http2.Http2ServerResponse类代码示例发布时间: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