fix(config): BIT-25761 fix andebol.net WP URL path and example config loading

- Exclude *.example.json files from loadSiteConfigs (previously only
  example.json was excluded, so andebol.net.example.json was loaded as
  a live config with placeholder credentials)
- Correct wp_url from https://andebol.net/wp-json to https://andebol.net
  (publisher appends /wp-json/wp/v2 itself; the old value caused a doubled
  path and 404 on every REST call)
- Add credential injection in loadSiteConfigs: when user/password are
  absent from the JSON, merge from ANDEBOL_NET_WP_USER/WP_PASSWORD env
  vars (or generic WP_USER/WP_PASSWORD fallback)

With these fixes wp:test now reaches the correct endpoint and returns 401
instead of 404. Remaining blocker: WP_USER in .env is still a placeholder.

Paperclip-Task-Id: BIT-25761
This commit is contained in:
Xika committed 2026-06-24 02:21:00 +00:00
1 parent 8f4575169d
commit 7d04eec305
2 files changed
+12 -3

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@
"writing_tone": "formal",
"audience_level": "general",
"wp_transport": "rest",
"wp_url": "https://andebol.net/wp-json",
"wp_url": "https://andebol.net",
"site_domain": "andebol.net",
"category_default": 1,
"category_infer": "andebol",
+11 -2
View File
@@ -39,10 +39,19 @@ function loadSiteConfigs() {
return fs
.readdirSync(sites_dir)
.filter((f) => f.endsWith('.json') && f !== 'example.json')
.filter((f) => f.endsWith('.json') && !f.endsWith('.example.json') && f !== 'example.json')
.map((f) => {
try {
return JSON.parse(fs.readFileSync(path.join(sites_dir, f), 'utf8'));
const cfg = JSON.parse(fs.readFileSync(path.join(sites_dir, f), 'utf8'));
// Inject credentials from env vars when absent from the site JSON.
// Per-site env takes precedence: ANDEBOL_NET_WP_USER / ANDEBOL_NET_WP_PASSWORD.
// Falls back to generic WP_USER / WP_PASSWORD for single-site setups.
if (!cfg.user || !cfg.password) {
const slug = (cfg.name || f.replace('.json', '')).toUpperCase().replace(/[^A-Z0-9]/g, '_');
cfg.user = process.env[`${slug}_WP_USER`] || process.env.WP_USER || cfg.user || '';
cfg.password = process.env[`${slug}_WP_PASSWORD`] || process.env.WP_PASSWORD || cfg.password || '';
}
return cfg;
} catch (err) {
logger.error(`Failed to load site config ${f}: ${err.message}`);
return null;