Module rendering views as images
- Description:
Module rendering views as images
- Source:
Methods
(static) renderView(options, cb) → {void}
- Description:
Function to render views as images
- Source:
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options required for rendering Properties
|
||||||||||||||||||||||||||||||||||||||||||
cb |
function | callback function called with the error value or the image data |
Returns:
void
- Type
- void
(inner) cdnOrigin() → {string|null}
- Description:
Origin of the configured CDN, when one is configured as an absolute url
cdn belongs to the dashboard's config rather than the api's. In the standard layout both live in the same tree and this finds it with no operator action; where the api is deployed without the dashboard the file is absent, and the origin is named in countlyConfig.render.allowedOrigins instead.
- Source:
Returns:
the CDN origin, or null when there is none to allow
- Type
- string | null
(inner) fetchChromeExecutablePath() → {Promise}
- Description:
Function to fetch Chrome executable
- Source:
Returns:
Promise
- Type
- Promise
(inner) originOf(url) → {string|null}
- Description:
Origin of a url, or null when it has none to speak of
A relative cdn ("" or "/assets/") has no origin and returns null here, which is correct: it is already served from the dashboard origin and needs no entry.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
url |
string | absolute url, or anything at all |
Returns:
the serialised origin, or null when there is not a real one
- Type
- string | null
(inner) renderAssetOrigins(host) → {Array.<string>}
- Description:
Origins the renderer may fetch subresources from
The dashboard's own origin, the configured CDN, the map tile provider the shipped dashboard uses, and anything the operator adds in countlyConfig.render.allowedOrigins (entries may be a bare origin or any url on it). Everything else is aborted.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
host |
string | dashboard origin plus the configured path |
Returns:
origins to allow, empty when the host itself cannot be parsed
- Type
- Array.<string>
(inner) sameOriginView(host, view) → {string|null}
- Description:
Check that a view stays on the dashboard, and return the url to navigate to
The view can come from a request (/o/render passes params.qstring.view through), and the url is built by concatenation. With the default countlyConfig.path of "" the prefix is exactly "http://localhost", so a view that does not begin with "/" rewrites the host instead of the path:
"@169.254.169.254/latest/meta-data/" -> host 169.254.169.254 ":8500/v1/kv/?recurse" -> host localhost:8500 ".internal.example/x" -> host localhost.internal.example
Parsing the concatenated url and comparing origins settles all of those at once, rather than trying to enumerate them. It also agrees with what Chromium will do with the same string, since both use the WHATWG url parser. Note that a private range denylist would be the wrong control here: the intended target is loopback.
The returned url is the concatenation itself, unchanged, so a configured countlyConfig.path keeps working exactly as before.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
host |
string | dashboard origin plus the configured path |
view |
string | view to render, expected to be a path on that dashboard |
Returns:
url to navigate to, or null when it leaves the dashboard origin
- Type
- string | null
(inner) saveScreenshot(image, path, source) → {Promise}
- Description:
Function to save screenshots
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
image |
Buffer | image data to store |
path |
String | path where image should be stored |
source |
String | who provided image |
Returns:
Promise
- Type
- Promise
(inner) timeout(ms) → {Promise}
- Description:
Function to set a timeout
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
ms |
number | Total milliseconds |
Returns:
Promise
- Type
- Promise