Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues/483 and add a basic Node example #484

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This library provides three components:
For the full API documentation go [here](#api).
For the full Class reference go [here](https://github.com/dailymotion/vast-client-js/blob/master/docs/api/class-reference.md)

To explore a practical example of how the vast client can be implemented, please visit this [link](https://githubbox.com/dailymotion/vast-client-js/tree/master/examples).
To explore a practical example of how the VAST client can be implemented in web applications please visit this [link](https://githubbox.com/dailymotion/vast-client-js/tree/master/examples/web). Additionally, use this [link](https://githubbox.com/dailymotion/vast-client-js/tree/master/examples/node) to learn how to use the VAST client in a basic Node application.

Complies with the [VAST 4.3 specification](https://iabtechlab.com/wp-content/uploads/2022/09/VAST_4.3.pdf) provided by the [Interactive Advertising Bureau (IAB)](https://www.iab.com/).

Expand Down
11 changes: 11 additions & 0 deletions examples/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { VASTClient } from '../../dist/vast-client-node.js';

const vastClient = new VASTClient();

async function parseSimpleInline() {
const parsedVast = await vastClient.get("https://statics.dmcdn.net/h/html/vast/simple-inline.xml");
// eslint-disable-next-line no-console
console.log(parsedVast);
}

await parseSimpleInline();
13 changes: 13 additions & 0 deletions examples/node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions examples/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "VASTClient-node-example",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Dailymotion <[email protected]> (https://developer.dailymotion.com/)"
"license": "MIT",
"description": "VAST Client node usage example"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import babel from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

const babelPlugin = babel({
babelrc: false,
Expand Down Expand Up @@ -29,6 +30,10 @@ const createNodeConfig = (filePath, minifiedOutput, notMinifiedOutput) => {
preferBuiltins: true,
}),
babelPlugin,
// We need commonjs for xmldom: https://github.com/xmldom/xmldom/issues/316
commonjs({
include: ["./node_modules/@xmldom/xmldom/lib/*.js"]
})
],
onwarn,
};
Expand Down
3 changes: 2 additions & 1 deletion src/fetcher/url_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ async function handleResponse(response) {
*/
function handleError(response) {
if (
window?.location?.protocol === 'https:' &&
util.isBrowserEnvironment() &&
window.location.protocol === 'https:' &&
response.url.includes('http://')
) {
return 'URLHandler: Cannot go from HTTPS to HTTP.';
Expand Down