You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 2 години
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const fs = require("fs");
  2. const path = require("path");
  3. const redis = require("redis");
  4. const bench_path = path.resolve(__dirname, "..", "..");
  5. function get_conf() {
  6. // defaults
  7. var conf = {
  8. redis_async_broker_port: "redis://localhost:12311",
  9. socketio_port: 3000,
  10. };
  11. var read_config = function (file_path) {
  12. const full_path = path.resolve(bench_path, file_path);
  13. if (fs.existsSync(full_path)) {
  14. var bench_config = JSON.parse(fs.readFileSync(full_path));
  15. for (var key in bench_config) {
  16. if (bench_config[key]) {
  17. conf[key] = bench_config[key];
  18. }
  19. }
  20. }
  21. };
  22. // get ports from bench/config.json
  23. read_config("config.json");
  24. read_config("sites/common_site_config.json");
  25. // set default site
  26. if (process.env.XhiveFramework_SITE) {
  27. conf.default_site = process.env.XhiveFramework_SITE;
  28. }
  29. if (fs.existsSync("sites/currentsite.txt")) {
  30. conf.default_site = fs.readFileSync("sites/currentsite.txt").toString().trim();
  31. }
  32. return conf;
  33. }
  34. function get_redis_subscriber(kind = "redis_socketio", options = {}) {
  35. const conf = get_conf();
  36. const host = conf[kind] || conf.redis_async_broker_port;
  37. return redis.createClient({ url: host, ...options });
  38. }
  39. module.exports = {
  40. get_conf,
  41. get_redis_subscriber,
  42. };