Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

51 строка
1.2 KiB

  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.FRAPPE_SITE) {
  27. conf.default_site = process.env.FRAPPE_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. };