Skip to content

Commit 3f942b4

Browse files
committed
fix window issue in Node, add Node example
1 parent 5d148f7 commit 3f942b4

14 files changed

+46
-6
lines changed

dist/vast-client-node.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,7 +2643,7 @@ async function handleResponse(response) {
26432643
* @returns {String | null}
26442644
*/
26452645
function handleError(response) {
2646-
if (window.location.protocol === 'https:' && response.url.includes('http://')) {
2646+
if (util.isBrowserEnvironment() && window.location.protocol === 'https:' && response.url.includes('http://')) {
26472647
return 'URLHandler: Cannot go from HTTPS to HTTP.';
26482648
}
26492649
if (response.status !== 200 || !response.ok) {
@@ -2664,8 +2664,9 @@ async function get(url, options) {
26642664
...options,
26652665
signal: controller.signal,
26662666
credentials: options.withCredentials ? 'include' : 'omit'
2667+
}).finally(() => {
2668+
clearTimeout(timer);
26672669
});
2668-
clearTimeout(timer);
26692670
const error = handleError(response);
26702671
if (error) {
26712672
return {

dist/vast-client-node.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vast-client.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,7 @@ async function handleResponse(response) {
26392639
* @returns {String | null}
26402640
*/
26412641
function handleError(response) {
2642-
if (window.location.protocol === 'https:' && response.url.includes('http://')) {
2642+
if (util.isBrowserEnvironment() && window.location.protocol === 'https:' && response.url.includes('http://')) {
26432643
return 'URLHandler: Cannot go from HTTPS to HTTP.';
26442644
}
26452645
if (response.status !== 200 || !response.ok) {
@@ -2660,8 +2660,9 @@ async function get(url, options) {
26602660
...options,
26612661
signal: controller.signal,
26622662
credentials: options.withCredentials ? 'include' : 'omit'
2663+
}).finally(() => {
2664+
clearTimeout(timer);
26632665
});
2664-
clearTimeout(timer);
26652666
const error = handleError(response);
26662667
if (error) {
26672668
return {

dist/vast-client.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/node/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { VASTClient } from '../../dist/vast-client-node.js';
2+
3+
const vastClient = new VASTClient();
4+
5+
async function parseSimpleInline() {
6+
const parsedVast = await vastClient.get("https://statics.dmcdn.net/h/html/vast/simple-inline.xml");
7+
// eslint-disable-next-line no-console
8+
console.log(parsedVast);
9+
}
10+
11+
await parseSimpleInline();

examples/node/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/node/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "test-node",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"type": "module",
6+
"scripts": {
7+
"start": "node index.js",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"description": ""
13+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/fetcher/url_handler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ async function handleResponse(response) {
3636
*/
3737
function handleError(response) {
3838
if (
39+
util.isBrowserEnvironment() &&
3940
window.location.protocol === 'https:' &&
4041
response.url.includes('http://')
4142
) {

0 commit comments

Comments
 (0)