@mimik/address-helper
v1.6.10
Published
IP Address helper for mimik microservices
Downloads
157
Readme
address-helper
Example
const addressHelper = require('@mimik/address-helper');
- address-helper
- ~getAddressByType(type, addresses) ⇒ object
- ~hrefId(serverSettings, basePath, resource, id) ⇒ URL.<string>
- ~addressTypeMaker(type, href, routingPort) ⇒ object
- ~addressFormat(type, protocol, ip, port, pathname, routingPort) ⇒ object
- ~addressFromNode(type, ip, node, routingPort) ⇒ object
- ~getAddress(node, localLinkNetworkId) ⇒ object
- ~updateAddresses(type, newAddress, addresses) ⇒ Array.<object>
- ~publicIpFromNode(node) ⇒ IP.<string>
- ~publicIpFromRequest(req) ⇒ IP.<string>
address-helper~getAddressByType(type, addresses) ⇒ object
Get the address by type from an array of address.
Kind: inner method of address-helper
Returns: object - Address by type.
Category: sync
| Param | Type | Description | | --- | --- | --- | | type | string | Type of address to return. | | addresses | Array.<object> | Addresses from which the specific address is retrieved. |
address-helper~hrefId(serverSettings, basePath, resource, id) ⇒ URL.<string>
Generate a href based of the given parameters.
Kind: inner method of address-helper
Returns: URL.<string> - Generated href.
Category: sync
| Param | Type | Description | | --- | --- | --- | | serverSettings | object | configuration to use to generate the href. | | basePath | PATH.<string> | Base path to use to generate the href. | | resource | PATH.<string> | Resource to use to generate the href. | | id | UUID.<string> | id to use to generate the href. |
address-helper~addressTypeMaker(type, href, routingPort) ⇒ object
Generate an address using the given parameters.
Kind: inner method of address-helper
Returns: object - Generated address.
Category: sync
| Param | Type | Description | | --- | --- | --- | | type | string | type to use the generate the address to return. | | href | URL.<string> | URL to use to generate the address to return. | | routingPort | number | Routing port to generate the address to return. |
address-helper~addressFormat(type, protocol, ip, port, pathname, routingPort) ⇒ object
Return an address using the given parameters.
Kind: inner method of address-helper
Returns: object - Generated address.
Category: sync
| Param | Type | Description | | --- | --- | --- | | type | string | type to use the generate the address to return. | | protocol | string | protocol to use to generate the address to return. | | ip | IP.<string> | Ip to use to generate the address to return. | | port | number | Port to use to generate the address to return. | | pathname | PATH.<string> | Path to add to generate the address to return. | | routingPort | number | Port to use to set the address to return. |
address-helper~addressFromNode(type, ip, node, routingPort) ⇒ object
Return an address corresponding to the given parameters.
Kind: inner method of address-helper
Summary: If the type is proxy
, a inversion using routingPort
is done.
Returns: object - Generated address corresponding to the given parameters.
Category: sync
| Param | Type | Description | | --- | --- | --- | | type | string | Type of address to return | | ip | IP.<string> | IP address to used to generate the address to return. | | node | object | Node to use to generate the address to return. | | routingPort | number | Routing port to use to generate the address to return. |
address-helper~getAddress(node, localLinkNetworkId) ⇒ object
Return the address to be used to reach the node.
Kind: inner method of address-helper
Summary: If localLinkNetworkId
is present, return the local address.
Otherwise return the proxy address, if it exists, or the public address.
Returns: object - Address to use to reach the node.
Category: sync
| Param | Type | Description | | --- | --- | --- | | node | object | Node from which to get the address. | | localLinkNetworkId | string | Id of the link local network to get the address from. |
address-helper~updateAddresses(type, newAddress, addresses) ⇒ Array.<object>
Add a new address of a specific type in the array of addresses.
Kind: inner method of address-helper
Returns: Array.<object> - Updated array of addresses.
Category: sync
| Param | Type | Description | | --- | --- | --- | | type | string | Type of address to add. | | newAddress | object | New address to add the the array of addresses. | | addresses | Array.<object> | Initial array of addresses to which the new address will be added. |
address-helper~publicIpFromNode(node) ⇒ IP.<string>
Get the public IP address from the registering node.
Kind: inner method of address-helper
Summary: If node is not defined return null
.
Returns: IP.<string> - Public IP address of the node.
Category: sync
| Param | Type | Description | | --- | --- | --- | | node | object | The node containing the public IP address. |
address-helper~publicIpFromRequest(req) ⇒ IP.<string>
Get the public IP address from the http request.
Kind: inner method of address-helper
Returns: IP.<string> - Public IP address of the component making the request.
| Env variable name | Description | Default | Comments |
| ----------------- | ----------- | ------- | -------- |
| IPV4 | when existent on non null, will translate an IPV6 address into IPV4 address when possible | | ::1
will be translated to `127.0.0.1``
If the environment variable IPV4 is set to true, the ip address will be translated to IPV4 address when possible, and ::1
will be translated to 127.0.0.1
.
Category: sync
| Param | Type | Description | | --- | --- | --- | | req | object | The http request to get the public IP address. |