From cf306e331a6b3a85f7ae41c7286a7cd2bb63785b Mon Sep 17 00:00:00 2001 From: Kouhai Date: Sat, 17 Feb 2024 13:38:16 -0800 Subject: [PATCH] th: maybe fix streaming --- .env.development | 1 + Procfile.dev | 2 +- streaming/index.js | 31 ++++++++++++++----------------- streaming/logging.js | 2 +- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/.env.development b/.env.development index cae26078f0..a03fb0f13b 100644 --- a/.env.development +++ b/.env.development @@ -1,5 +1,6 @@ LOCAL_DOMAIN=localhost ALTERNATE_DOMAINS=mastodon.internal +STREAMING_API_BASE_URL=https://streaming.mastodon.internal DB_HOST=$PWD/data/postgres DB_USER=mastodon diff --git a/Procfile.dev b/Procfile.dev index f81333b04c..ba0ceddee3 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,4 +1,4 @@ web: env PORT=3000 RAILS_ENV=development bundle exec puma -C config/puma.rb sidekiq: env PORT=3000 RAILS_ENV=development bundle exec sidekiq -stream: env PORT=4000 yarn workspace @mastodon/streaming start +stream: env PORT=4000 yarn workspace @mastodon/streaming start | npx pino-pretty webpack: bin/webpack-dev-server diff --git a/streaming/index.js b/streaming/index.js index 3e8086e5ea..5e7b350f65 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -25,21 +25,14 @@ const dotenvFile = environment === 'production' ? '.env.production' : '.env.deve const dotenvFileLocal = `${dotenvFile}.local` // Replicate dotenv-rails's behavior -dotenv.config({ - path: '.env', -}); -dotenv.config({ - path: path.resolve(__dirname, path.join('..', dotenvFile)) -}); -dotenv.config({ - path: '.env.local', -}); -dotenv.config({ - path: environment === 'production' ? '.env.production.local' : '.env.development.local', -}); -dotenv.config({ - path: path.resolve(__dirname, path.join('..', dotenvFileLocal)) -}); +const projectDir = path.resolve(__dirname, '..') +const dotenvFiles = ['.env', dotenvFile, '.env.local', dotenvFileLocal] + .map(s => path.join(projectDir, s)); +dotenvFiles.forEach(path => dotenv.config({path})); + +if (process.env.REDIS_URL && process.env.PWD) { + process.env.REDIS_URL = process.env.REDIS_URL.replace(/\$PWD\b|$\{PWD\}/, projectDir); +} initializeLogLevel(process.env, environment); @@ -81,7 +74,7 @@ const createRedisClient = async (config) => { client = new Redis(redisUrl, redisParams);; } // @ts-ignore - client.on('error', (err) => log.error('Redis Client Error!', err)); + client.on('error', (err) => logger.error(err, 'Redis Client Error!')); return client; }; @@ -205,10 +198,14 @@ const redisConfigFromEnv = (env) => { redisParams.path = env.REDIS_URL.slice(7); } + const redisUrlParams = env.REDIS_URL ? { + redisUrl: env.REDIS_URL, + } : {}; + return { redisParams, redisPrefix, - redisUrl: env.REDIS_URL, + ...redisUrlParams, }; }; diff --git a/streaming/logging.js b/streaming/logging.js index 64ee474875..6184df2c03 100644 --- a/streaming/logging.js +++ b/streaming/logging.js @@ -56,7 +56,7 @@ const logger = pino({ 'req.headers.cookie', 'req.query.access_token' ] - } + }, }); const httpLogger = pinoHttp({