-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathservice.lua
31 lines (23 loc) · 961 Bytes
/
service.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
print "loaded"
local os = require("os")
local ld = require("launchdarkly_server_sdk")
local get_from_env_or_default = require("get_from_env_or_default")
-- Set MY_SDK_KEY to your LaunchDarkly SDK key.
local MY_SDK_KEY = ""
-- Set MY_FLAG_KEY to the boolean-type feature flag key you want to evaluate.
local MY_FLAG_KEY = ""
local config = {}
local sdk_key = get_from_env_or_default("LAUNCHDARKLY_SDK_KEY", MY_SDK_KEY)
local client = ld.clientInit(sdk_key, 1000, config)
local flag_key = get_from_env_or_default("LAUNCHDARKLY_FLAG_KEY", MY_FLAG_KEY)
core.register_service("launchdarkly", "http", function(applet)
applet:start_response()
local user = ld.makeContext({
user = {
key = "example-user-key",
name = "Sandy"
}
})
local flag_value = client:boolVariation(user, flag_key, false)
applet:send("<p>The " .. flag_key .. " feature flag evaluates to " .. tostring(flag_value) .. ".</p>")
end)