Skip to content

Commit

Permalink
updting logging and sample apps
Browse files Browse the repository at this point in the history
  • Loading branch information
sigewuzhere committed Jan 13, 2020
1 parent 8985a27 commit 31ba38c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
6 changes: 4 additions & 2 deletions samples/console/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
var configcat = require("configcat-node");

var configCatClient = configcat.createClientWithAutoPoll('PKDVCLf-Hq-h-kCzMp-L7Q/HhOWfwVtZ0mb30i9wi17GQ', { pollIntervalSeconds: 2 });
const logger = configcat.createConsoleLogger(3); // Setting log level to 3 (= Info) to show detailed feature flag evaluation

const configCatClient = configcat.createClientWithAutoPoll('PKDVCLf-Hq-h-kCzMp-L7Q/HhOWfwVtZ0mb30i9wi17GQ', { pollIntervalSeconds: 2, logger: logger });
// You can instantiate the client with different polling modes. See the Docs: https://docs.configcat.com/docs/sdk-reference/js/#polling-modes

configCatClient.getValueAsync("isAwesomeFeatureEnabled", false).then(value => {
console.log("isAwesomeFeatureEnabled: " + value);
});

var userObject = { identifier: "#SOME-USER-ID#", email: "[email protected]" };
const userObject = { identifier: "#SOME-USER-ID#", email: "[email protected]" };
// Read more about the User Object: https://docs.configcat.com/docs/sdk-reference/js/#user-object
configCatClient.getValueAsync("isPOCFeatureEnabled", false, userObject).then(value => {
console.log("isPOCFeatureEnabled: " + value);
Expand Down
29 changes: 14 additions & 15 deletions samples/expresswithdocker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@ const APIKEY = "PKDVCLf-Hq-h-kCzMp-L7Q/HhOWfwVtZ0mb30i9wi17GQ";
const PORT = 8088;
const SAMPLE_KEY = "isAwesomeFeatureEnabled";

var express=require("express");
var express = require("express");
var configcat = require("configcat-node");
var app=express();
var app = express();

let configCatClient = configcat.createClient(APIKEY);

app.get("/",function(req,res)
{
var logger = configcat.createConsoleLogger(3); // Setting log level to 3 (= Info) to show detailed feature flag evaluation

let configCatClient = configcat.createClient(APIKEY, { logger: logger });

app.get("/", function (req, res) {
res.send("Express is running...");
});

app.get("/" + SAMPLE_KEY,async function(req,res)
{
const feature2 = await configCatClient.getValueAsync(SAMPLE_KEY, false)
app.get("/" + SAMPLE_KEY, async function (req, res) {
const feature2 = await configCatClient.getValueAsync(SAMPLE_KEY, false)
console.log(SAMPLE_KEY + ": " + feature2);
res.send(SAMPLE_KEY+ " -> " + feature2);

res.send(SAMPLE_KEY + " -> " + feature2);
});

app.get("/keys",async function(req,res)
{
app.get("/keys", async function (req, res) {
const keys = await configCatClient.getAllKeysAsync();
console.log("keys: " + keys);

res.send("keys: '" + keys + "'");

});

var server=app.listen(PORT,function() {});
app.listen(PORT, function () { });
6 changes: 4 additions & 2 deletions src/config-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ export class HttpConfigFetcher implements IConfigFetcher {
} else if (response && response.statusCode === 200) {
callback(new ProjectConfig(new Date().getTime(), response.body, response.headers.etag as string));
} else {
options.logger.log("Failed to download config from ConfigCat. Status:" + (response && response.statusCode) + " - " + (response && response.statusMessage));
options.logger.error("Failed to download feature flags & settings from ConfigCat. Status:" + (response && response.statusCode) + " - " + (response && response.statusMessage));
options.logger.info("Double-check your API KEY on https://app.configcat.com/apikey");
callback(lastProjectConfig);
}
}).catch((reason) => {
const response = reason.response;
if (response && response.status === 304) {
callback(new ProjectConfig(new Date().getTime(), JSON.stringify(lastProjectConfig.ConfigJSON), response.headers.get('etag')));
} else {
options.logger.log("Failed to download config from ConfigCat. Status:" + (response && response.statusCode) + " - " + (response && response.statusMessage));
options.logger.error("Failed to download feature flags & settings from ConfigCat. Status:" + (response && response.statusCode) + " - " + (response && response.statusMessage));
options.logger.info("Double-check your API KEY on https://app.configcat.com/apikey");
callback(lastProjectConfig);
}
});
Expand Down

0 comments on commit 31ba38c

Please sign in to comment.