本文整理汇总了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();
});
}
示例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();
});
示例3: function
server = app.listen(process.env.PORT || 8080, function() {
console.log(`CompassHB ready for requests on ${server.address().address} port ${server.address().port}!`);
});
示例4:
const httpServer: HttpServer = app.listen(8000, 'localhost', () => {
const {address, port} = httpServer.address();
console.log('Listening on %s:%s', address, port);
});
示例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}`;
}
示例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);
});