Skip to content

Commit f36142d

Browse files
committed
Bump versions of packages
1 parent 35e8fd1 commit f36142d

File tree

4 files changed

+812
-6
lines changed

4 files changed

+812
-6
lines changed

node/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This Node application demonstrates a simple, barebones Metabase dashboard embedd
44

55
## Prerequisites
66

7-
- **Metabase**. You should have already completed the setup detailed in the [README](../README.md) for this repository, which shows you how to get an instance of Metabase up and running in the [metabase](../metabase) directory of this repository.
7+
- **Metabase**. You should have already completed the setup detailed in the [README](../README.md) for this repository, which shows you how to get an instance of Metabase up and running in the [metabase](../metabase) directory of this repository. You have to also configure Metabase for public sharing.
88

99
- **Node**. You'll need [Node](https://nodejs.org/en/) installed on your machine to run the application.
1010

@@ -14,15 +14,15 @@ This Node application demonstrates a simple, barebones Metabase dashboard embedd
1414

1515
1. In a new terminal session, `cd` into this directory.
1616

17-
2. Run `yarn install` or `npm install` to install the application's dependencies.
17+
2. Run `yarn install` to install the application's dependencies.
1818

19-
3. Once the application dependencies are installed, run:
19+
3. Once the application dependencies are installed, run `yarn start` or:
2020

2121
```shell
2222
node index.js
2323
```
2424

25-
4. Open your browser to [localhost:3000](http://localhost:3000) (or the port where Metabase is running).
25+
4. Open your browser to [localhost:3001](http://localhost:3001) (or the port where this application is running).
2626

2727
Explore the app to learn more about embedding Metabase charts and dashboards in applications. You can also check out the links to more documentation in the parent repository's main [README](../README.md).
2828

node/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const PORT = process.env["PORT"] ? parseInt(process.env["PORT"]) : 3001;
66

77
// these should match the settings in your Metabase instance
88
let MB_SITE_URL = "http://localhost:3000";
9-
let MB_EMBEDDING_SECRET_KEY = "a1c0952f3ff361f1e7dd8433a0a50689a004317a198ecb0a67ba90c73c27a958";
9+
let MB_EMBEDDING_SECRET_KEY = "c39fcfd02abd76b0ad200d1eada354f136c383638dcfc189253b9b8e0dd13e46";
1010

1111
function checkAuth(req, res, next) {
1212
const userId = req.session.userId;
@@ -88,6 +88,20 @@ app.get("/signed_dashboard/:id", checkAuth, (req, res) => {
8888
res.render("dashboard", { userId: req.params.id, iframeUrl: iframeUrl });
8989
})
9090

91+
app.get("/signed_public_dashboard/", (req, res) => {
92+
const userId = req.session.userId;
93+
const unsignedToken = {
94+
resource: { dashboard: DASHBOARD_ID },
95+
params: { id: userId },
96+
exp: Math.round(Date.now() / 1000) + (10 * 60) // 10 minute expiration
97+
};
98+
// sign the JWT token with our secret key
99+
const signedToken = jwt.sign(unsignedToken, MB_EMBEDDING_SECRET_KEY);
100+
// construct the URL of the iframe to be displayed
101+
const iframeUrl = `${MB_SITE_URL}/embed/dashboard/${signedToken}`;
102+
res.render("dashboard", { userId: req.params.id, iframeUrl: iframeUrl });
103+
})
104+
91105
app.listen(PORT, () => {
92106
console.log("Example app listening on port " + PORT + "!");
93107
});

node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"express": "^4.17.1",
77
"express-session": "^1.17.1",
88
"jsonwebtoken": "^8.5.1",
9-
"pug": "^2.0.4"
9+
"pug": "^3.0.2"
1010
},
1111
"scripts": {
1212
"start": "node index.js"

0 commit comments

Comments
 (0)