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


TypeScript Server.address方法代碼示例

本文整理匯總了TypeScript中http.Server.address方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Server.address方法的具體用法?TypeScript Server.address怎麽用?TypeScript Server.address使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在http.Server的用法示例。


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

示例1: 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

示例2: it

 it("should respond OK! when started", done => {
   expect(server.listening).toEqual(true);
   const req = http.request(
     {
       host: "localhost",
       port: server.address().port,
       path: "/status",
       method: "GET",
     },
     res => {
       let data = "";
       res.on("data", chunk => {
         data += chunk;
       });
       res.on("end", () => {
         expect(data).toEqual("OK!");
         done();
       });
     },
   );
   req.end();
 });
開發者ID:SonarSource,項目名稱:sonar-javascript,代碼行數:22,代碼來源:server.test.ts

示例3: function

server = app.listen(process.env.PORT || 8080, function() {
  console.log(`CompassHB ready for requests on ${server.address().address} port ${server.address().port}!`);
});
開發者ID:CompassHB,項目名稱:web,代碼行數:3,代碼來源:server.ts

示例4:

const httpServer: HttpServer = app.listen(8000, 'localhost', () => {
  const {address, port} = httpServer.address();
  console.log('Listening on %s:%s', address, port);
});
開發者ID:AviFix,項目名稱:angular2typescript,代碼行數:4,代碼來源:auction.ts

示例5: getServerUrl

function getServerUrl(server: Server) {
  const address = server.address() as AddressInfo;

  // tslint:disable-next-line:no-http-string
  return `http://127.0.0.1:${address.port}`;
}
開發者ID:WhisperSystems,項目名稱:Signal-Desktop,代碼行數:6,代碼來源:macos.ts

示例6: function

server.on('listening', function() {
  var addr: any = server.address();
  var bind: string = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
  console.log('Listening on ' + bind);
});
開發者ID:flyingsky,項目名稱:expressts-seed-project,代碼行數:5,代碼來源:app.ts


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