Skip to content

Commit 0fdbefe

Browse files
authored
Merge pull request #60 from metabase/update-dependencies
Update dependencies and change the documentation
2 parents 11bcff0 + dacdccf commit 0fdbefe

File tree

11 files changed

+3346
-3776
lines changed

11 files changed

+3346
-3776
lines changed

README.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,19 @@ If you'd like to remove the "Powered by Metabase" attribution, check out our [En
1616

1717
## Prerequisites
1818

19-
- Java version 8.x or 11.x. [Install OpenJDK](https://openjdk.java.net/install/).
19+
- Java version 11 + [Install OpenJDK](https://openjdk.java.net/install/).
2020

2121
## Set up Metabase
2222

2323
We'll first need to set up a running instance of Metabase to serve the embedded dashboards.
2424

25-
1. If you already have an instance of Metabase running on your machine, shut it down.
25+
1. If you already have an instance of Metabase running on your machine, shut it down. Then download and run Metabase according to the guides in our [install section](https://www.metabase.com/docs/latest/operations-guide/installing-metabase.html).
2626

2727
2. Open up a terminal and clone this repo to your machine.
2828

2929
3. `cd` into embedding-reference-apps.
3030

31-
3. Run the the prepare script.
32-
33-
```shell
34-
./prepare.sh
35-
```
36-
37-
The prepare.sh script downloads the latest version of Metabase to this repository's [metabase](/metabase) directory, changes into that directory, and runs the jar:`java -jar metabase.jar`.
38-
39-
Metabase will log its progress in the terminal as the jar runs. Once you see the line, "Metabase Inititalization COMPLETE", open your browser to [localhost:3000](http://localhost:3000) to see that Metabase is up and running.
31+
3. Run any example depending on the programming language you choose.
4032

4133
## Running the apps
4234

laravel/embedded_analytics/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
1111
},
1212
"devDependencies": {
13-
"axios": "^0.19",
13+
"axios": "^0.21.1",
1414
"bootstrap-sass": "^3.4.1",
15-
"cross-env": "^7.0",
16-
"jquery": "^3.5.0",
17-
"laravel-mix": "^5.0.1",
18-
"lodash": "^4.17.13",
19-
"vue": "^2.1.10"
15+
"cross-env": "^7.0.3",
16+
"jquery": "^3.6.0",
17+
"laravel-mix": "^6.0.18",
18+
"lodash": "^4.17.21",
19+
"vue": "^2.6.12"
2020
}
2121
}

laravel/embedded_analytics/yarn.lock

Lines changed: 3023 additions & 3432 deletions
Large diffs are not rendered by default.

metabase/metabase.db.mv.db

-652 KB
Binary file not shown.

metabase/metabase.db.trace.db

Lines changed: 0 additions & 3 deletions
This file was deleted.

node/README.md

Lines changed: 3 additions & 3 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](https://www.metabase.com/docs/latest/administration-guide/12-public-links.html) or [embedding](https://www.metabase.com/docs/latest/administration-guide/13-embedding.html).
88

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

@@ -16,13 +16,13 @@ This Node application demonstrates a simple, barebones Metabase dashboard embedd
1616

1717
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:3001](http://localhost:3001).
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: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
const express = require("express");
22
const session = require("express-session");
3-
const bodyParser = require("body-parser");
43
const jwt = require("jsonwebtoken");
54

65
const PORT = process.env["PORT"] ? parseInt(process.env["PORT"]) : 3001;
76

87
// these should match the settings in your Metabase instance
98
let MB_SITE_URL = "http://localhost:3000";
10-
let MB_EMBEDDING_SECRET_KEY = "a1c0952f3ff361f1e7dd8433a0a50689a004317a198ecb0a67ba90c73c27a958";
9+
let MB_EMBEDDING_SECRET_KEY = "c39fcfd02abd76b0ad200d1eada354f136c383638dcfc189253b9b8e0dd13e46";
1110

1211
function checkAuth(req, res, next) {
1312
const userId = req.session.userId;
@@ -32,7 +31,7 @@ const app = express();
3231

3332
app.set("view engine", "pug");
3433
app.use(session({ secret: "FIXME", resave: false, saveUninitialized: true }));
35-
app.use(bodyParser.urlencoded({ extended: false }));
34+
app.use(express.urlencoded({ extended: false }));
3635

3736
app.get("/", (req, res) => res.render("index"));
3837

@@ -89,6 +88,20 @@ app.get("/signed_dashboard/:id", checkAuth, (req, res) => {
8988
res.render("dashboard", { userId: req.params.id, iframeUrl: iframeUrl });
9089
})
9190

91+
app.get("/signed_public_dashboard/", (req, res) => {
92+
const userId = req.session.userId;
93+
const unsignedToken = {
94+
resource: { dashboard: 1 },
95+
params: { },
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("public_dashboard", { iframeUrl: iframeUrl });
103+
})
104+
92105
app.listen(PORT, () => {
93106
console.log("Example app listening on port " + PORT + "!");
94107
});

node/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
"version": "1.0.0",
44
"main": "index.js",
55
"dependencies": {
6-
"body-parser": "^1.19.0",
76
"express": "^4.17.1",
87
"express-session": "^1.17.1",
98
"jsonwebtoken": "^8.5.1",
10-
"pug": "^2.0.4"
9+
"pug": "^3.0.2"
1110
},
1211
"scripts": {
1312
"start": "node index.js"

node/views/public_dashboard.pug

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
extends layout.pug
2+
3+
block content
4+
h1 Signed dashboards without parameters</h1>
5+
6+
p
7+
This is an example of a signed embedded dashboard. We haven't signed any parameters, but we have signed the resource id (in this case dashboard 1). This is means that only application with the signing key are allowed to embed a Metabase resource (vs the public link which can be copy/pasted and shared). Signed embeds can also be set to have an expiration time, which further improves security.
8+
9+
p
10+
To embed this dasbhoard in a webpage (as below), you'll need to generate a url on the server by signing a dictionary specifying the resource and it's signed parameters as below
11+
12+
13+
pre.
14+
payload = {
15+
"resource": {"dashboard": 1},
16+
"params": { }
17+
}
18+
19+
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256").decode('utf8')
20+
21+
iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true"
22+
23+
p In the place you wish to embed the chart in your HTML, insert the below:
24+
25+
pre.
26+
&lt;iframe
27+
src="http://{% templatetag openvariable %}iframeUrl{% templatetag closevariable %}"
28+
frameborder="0"
29+
width="800"
30+
height="600"
31+
allowtransparency
32+
&gt;&lt;/iframe&gt;
33+
34+
a(href="/") Go back to a global view
35+
36+
p This results in the below when put together
37+
38+
h2 Global Order Stats
39+
40+
iframe(src=iframeUrl
41+
width="1200"
42+
height="800"
43+
frameborder="0")
44+
45+

0 commit comments

Comments
 (0)