本文整理匯總了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);
});