Skip to content

Commit 4edba5f

Browse files
chadiiichadiii
chadiii
authored and
chadiii
committed
adding flagship sdk and updating without_module example
1 parent 28ec129 commit 4edba5f

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

example/backend/index.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const express = require('express')
22
const app = express()
33
const port = 8081
4+
const { Flagship } = require("@flagship.io/js-sdk");
45

56
app.set('etag', false)
67

@@ -14,11 +15,31 @@ app.get('/with_module', (req, res) => {
1415
})
1516

1617
app.get('/without_module', (req, res) => {
17-
if (req.get('user-agent').includes("Chrome")) {
18-
res.send("Chrome")
19-
} else {
20-
res.send("Firefox")
21-
}
18+
19+
Flagship.start("c0n48jn5thv01k0ijmo0", "BsIK86oh7c12c9G7ce4Wm1yBlWeaMf3t1S0xyYzI");
20+
21+
const visitor_id = req.get('x-visitor-id')
22+
const visitor_context = req.get('x-visitor-context')
23+
const [visitorContextKey, visitorContextValue] = visitor_context.split(':');
24+
25+
const visitor = Flagship.newVisitor({
26+
visitorId: visitor_id,
27+
context: { [visitorContextKey]: visitorContextValue }
28+
});
29+
30+
visitor.on("ready", (error) => {
31+
if (error) {
32+
res.status(500).send("Internal Error (Visitor)")
33+
return;
34+
}
35+
const flagKey = visitor.getFlag("IsVIP", false)._key;
36+
const flagValue = visitor.getFlag("IsVIP", false).getValue();
37+
res.status(200).send(
38+
`

Visitor id : ${visitor_id}

39+

Visitor context : ${visitor_context}

40+

Flags : ${flagKey}: ${flagValue}

41+
`)
42+
});
2243
})
2344

2445
app.listen(port, () => {

example/backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"author": "",
1515
"license": "ISC",
1616
"dependencies": {
17+
"@flagship.io/js-sdk": "^3.0.4",
1718
"express": "^4.17.2",
1819
"nodemon": "^2.0.15",
1920
"pm2": "^5.2.0"

example/config/nginx-conf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ server {
100100

101101
add_header X-Proxy-Cache $upstream_cache_status;
102102

103-
proxy_set_header X-Flagship-Flags "noflag";
103+
set $visitor_context browser:$browser_type;
104+
105+
proxy_set_header X-Visitor-Id $request_id;
106+
proxy_set_header X-Visitor-Context $visitor_context;
104107

105108
default_type text/html;
106109

0 commit comments

Comments
 (0)