Skip to content
Merged
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ This project was created using NodeJS 18.18. This application aims to demonstrat
3. Finally, run the application using the following command

```bash
node embed.js
node tokengeneration.js
```

4. After the application has started, it will display a URL in the `command line interface`, typically something like (e.g., <http://localhost:8080/>). Copy this URL and paste it into your default web browser.
Expand All @@ -67,7 +67,7 @@ This project was created using NodeJS 18.18. This application aims to demonstrat
* Finally, run the application using the following command.

```bash
node embed.js
node tokengeneration.js
```

* After the application has started, it will display a URL in the `command line interface`, typically something like (e.g., <http://localhost:8080/>). Copy this URL and paste it into your default web browser.
Expand All @@ -86,4 +86,4 @@ Look at the Bold BI Embedding sample to live demo [here](https://samples.boldbi.

## Documentation

A complete Bold BI Embedding documentation can be found on [Bold BI Embedding Help](https://help.boldbi.com/embedded-bi/javascript-based/?utm_source=github&utm_medium=backlinks).
A complete Bold BI Embedding documentation can be found on [Bold BI Embedding Help](https://help.boldbi.com/embedded-bi/javascript-based/?utm_source=github&utm_medium=backlinks).
75 changes: 0 additions & 75 deletions embed.js

This file was deleted.

Binary file modified images/dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 41 additions & 33 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
<html>
<head>
<script type="text/javascript" src="https://cdn.boldbi.com/embedded-sdk/latest/boldbi-embed.js"></script>
</head>
<body onload="embedSample();">
<div id="dashboard"></div>
<script>

//For Bold BI Enterprise edition, it should be like `site/site1`. For Bold BI Cloud, it should be empty string.
var siteIdentifier = configjson.SiteIdentifier;

//Your Bold BI application environment. (If Cloud, you should use `cloud`, if Enterprise, you should use `enterprise`)
var environment = configjson.Environment;
<head>
<script type="text/javascript" src="https://cdn.boldbi.com/embedded-sdk/latest/boldbi-embed.js"></script>
</head>

//Item id of the dashboard in the Bold BI server`
var dashboardId = configjson.DashboardId;
<body onload="embedSample();">
<div id="dashboard"></div>
<script>

var embedType = configjson.EmbedType;
//For Bold BI Enterprise edition, it should be like `site/site1`. For Bold BI Cloud, it should be empty string.
var siteIdentifier = configjson.SiteIdentifier;

//Bold BI Server URL (ex: http://localhost:5000/bi, http://demo.boldbi.com/bi)
var rootUrl = configjson.ServerUrl;
//Item id of the dashboard in the Bold BI server
var dashboardId = configjson.DashboardId;

//Url of the GetDetails(API) in this application
var authorizationUrl="http://localhost:8080/embeddetail/get";
//Bold BI Root URL (ex: http://localhost:5000/bi, http://demo.boldbi.com/bi)
var rootUrl = configjson.ServerUrl;

function embedSample() {
//Backend Url of the token generation in this application
var tokenGenerationUrl = "/TokenGeneration";

function embedSample() {
getEmbedToken().then(accessToken => {
var boldbiEmbedInstance = BoldBI.create({
serverUrl: rootUrl + "/" + siteIdentifier,
dashboardId: dashboardId,
dashboardId: dashboardId,
embedContainerId: "dashboard",// This should be the container id where you want to embed the dashboard
embedType: embedType,
environment: environment,
mode: BoldBI.Mode.View,
height: "100%",
width: "100%",
authorizationServer: {
url: authorizationUrl
},
expirationTime: "100000",
embedToken: accessToken,
});
boldbiEmbedInstance.loadDashboard();
}
</script>
</body>
</html>
}).catch(error => {
console.error("Failed to get embed token:", error);
});
}

function getEmbedToken() {
return fetch(tokenGenerationUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({})
})
.then(response => {
if (!response.ok) throw new Error("Token fetch failed");
return response.text();
});
}
</script>
</body>

</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "NodeJS",
"version": "1.0.0",
"description": "",
"main": "embed.js",
"main": "tokengeneration.js",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.2",
Expand Down
80 changes: 80 additions & 0 deletions tokengeneration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
var fs = require("fs");
var http = require("http");
var https = require("https");
var url = require("url");
var express = require('express');
var cors = require('cors');
var app = express();

app.use(cors());
// Parse JSON bodies (as sent by API clients)
app.use(express.json());

// Read JSON as UTF-8 and strip BOM if present to avoid parse errors
var appconfig = JSON.parse(fs.readFileSync('embedConfig.json', 'utf8').replace(/^\uFEFF/, ''));

var configjson ={"DashboardId": appconfig.DashboardId, "ServerUrl": appconfig.ServerUrl, "SiteIdentifier": appconfig.SiteIdentifier, "Environment": appconfig.Environment, "EmbedType": appconfig.EmbedType};

app.post('/TokenGeneration', function (req, response) {
const embedDetails = {
email: appconfig.UserEmail,
serverurl: appconfig.ServerUrl,
siteidentifier: appconfig.SiteIdentifier,
embedsecret: appconfig.EmbedSecret,
dashboard: { // Dashboard ID property is mandatory only when using BoldBI version 14.1.11.
id: appconfig.DashboardId
}
}

const parsedUrl = new URL(embedDetails.serverurl);
const postData = JSON.stringify(embedDetails);
const client = parsedUrl.protocol === 'https:' ? https : http;
const options = {
hostname: parsedUrl.hostname,
port: parsedUrl.port || (parsedUrl.protocol === 'https:' ? 443 : 80),
path: `${parsedUrl.pathname}/api/${embedDetails.siteidentifier}/embed/authorize`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
};

const requ = client.request(options, res => {
let result = '';
res.setEncoding('utf8');
res.on('data', chunk => result += chunk);
res.on('end', () => {
const resultparse = JSON.parse(result); // Parse the response
response.send(resultparse?.Data?.access_token);
});
});

requ.on('error', (e) => {
console.error("Error fetching embed token:", e.message);
});

requ.write(postData);
requ.end();
})

app.get("/",function (request, response) {

var pathname = url.parse(request.url).pathname;
console.log("Request for " + pathname + " received.");

response.writeHead(200);

if(pathname == "/") {
html = fs.readFileSync("index.html", "utf8");
html = html.replace("<script>","<script>var configjsonstring='"+JSON.stringify(configjson)+"';var configjson=JSON.parse(configjsonstring);");
response.write(html);
}
response.end();
})

var server = app.listen(8080, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})