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

TypeScript http.Server类代码示例

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

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



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

示例1: Promise

    return protractorUtils.findFreeTcpPort().then(port => {
      const app = new http.Server();

      app.on('request', (req, res) => {
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.write('Hello World');
        res.end('\n');
      });

      browser.baseUrl = `http://localhost:${port}`;

      return new Promise(resolve => { app.listen(port, () => { resolve(); }); });
    });
开发者ID:BobChao87,项目名称:angular,代码行数:13,代码来源:conf.ts


示例2: catch

 .catch(error => {
   startupError = error;
   try {
     wsServer.close();
   } catch (_error) {}
   try {
     httpServer.close();
   } catch (_error) {}
 })
开发者ID:edhager,项目名称:intern,代码行数:9,代码来源:Server.ts


示例3: init

export async function init(){
	console.log('starting IDE');

	await check_lockfile()
		.catch( (e: Error) => console.log('error checking lockfile', e) );

	// setup webserver 
	const app: express.Application = express();
	const server: http.Server = new http.Server(app);
	setup_routes(app);

	// start serving the IDE on port 80
	server.listen(80, () => console.log('listening on port', 80) );

	// initialise websocket
	socket_manager.init(server);

	TerminalManager.init();
}
开发者ID:BelaPlatform,项目名称:Bela,代码行数:19,代码来源:main.ts


示例4: Promise

		return new Promise((resolve) => {
			const server = this.server = createServer((request: IncomingMessage, response: ServerResponse) => {
				return this._handler(request, response);
			});
			this._sessions = {};
			this._codeCache = {};

			const sockets: Socket[] = [];

			// If sockets are not manually destroyed then Node.js will keep itself running until they all expire
			after(server, 'close', function () {
				let socket: Socket;
				while ((socket = sockets.pop())) {
					socket.destroy();
				}
			});

			server.on('connection', socket => {
				this.executor.log('HTTP connection opened');
				sockets.push(socket);

				// Disabling Nagle improves server performance on low-latency connections, which are more common
				// during testing than high-latency connections
				socket.setNoDelay(true);

				socket.on('close', function () {
					let index = sockets.indexOf(socket);
					index !== -1 && sockets.splice(index, 1);
				});
			});

			this._wsServer = new WebSocket.Server({ port: this.port + 1 });
			this._wsServer.on('connection', client => {
				this.executor.log('WebSocket connection opened:', client);
				this._handleWebSocket(client);
			});
			this._wsServer.on('error', error => {
				this.executor.emit('error', error);
			});

			server.listen(this.port, resolve);
		});
开发者ID:bryanforbes,项目名称:intern,代码行数:42,代码来源:Server.ts


示例5: post

  function post(data): Promise<string> {
    const options = {
      host: "localhost",
      port: server.address().port,
      path: "/analyze",
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
    };

    return new Promise((resolve, reject) => {
      let response = "";

      const req = http.request(options, res => {
        res.on("data", chunk => {
          response += chunk;
        });

        res.on("end", () => resolve(response));
      });

      req.on("error", reject);

      req.write(data);
      req.end();
    });
  }
开发者ID:SonarSource,项目名称:sonar-javascript,代码行数:28,代码来源:server.test.ts


示例6: after

  after(() => {

    if (serverToClose) {
      serverToClose.close();
    }

  });
开发者ID:jw120,项目名称:fcc-url-shortener,代码行数:7,代码来源:server_spec.ts


示例7: after

  after(() => {

    if (server) {
      server.close();
    }

  });
开发者ID:jw120,项目名称:fcc-timestamp,代码行数:7,代码来源:server_spec.ts


示例8: Promise

 return new Promise((resolve, reject) => {
     server.close((err) => {
         if (err) {
             return reject(err);
         } 
         resolve();
     })
 })
开发者ID:rajivnarayana,项目名称:expressjs-typescript-starter,代码行数:8,代码来源:utils.ts


示例9: listen

  listen(): void {
    this.server.listen(this.port, () => {
      console.log(`  > Running socket on port: ${this.port}`);
    });

    this.io.on('connection', (socket: socketio.Socket) => {
      socket.on('live_data', (value: boolean) => {
        this.useTrainingData = value;
      });
    });
  }
开发者ID:AIED-ECNU,项目名称:tfjs-examples,代码行数:11,代码来源:socket.ts


示例10: after

 after(() => {
     server.close();
     
     let cache = require.cache;
     
     for (let path of Object.keys(cache)) {
         if (/(?:[\\/]modules|-routes)[\\/]/.test(path)) {
             delete cache[path];
         }
     }
 });
开发者ID:Regina-Cupido-Officium,项目名称:vio,代码行数:11,代码来源:sites.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript http.ServerResponse类代码示例发布时间:2022-05-25
下一篇:
TypeScript http.IncomingMessage类代码示例发布时间: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