All files / services/shared signedAxios.js

100% Statements 21/21
60% Branches 3/5
100% Functions 0/0
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 223x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 9x 9x 3x 3x 3x  
const axios = require('axios');
const { addInternalKey } = require('./internalAuth');
 
const CONFIG_SERVICE_URL = process.env.CONFIG_SERVICE_URL || 'http://config-service:8000';
const SERVICE_NAME = process.env.SERVICE_NAME || 'unknown';
 
/**
 * Client axios pour les appels internes au config-service.
 * Ajoute automatiquement le header x-internal-token (token signé HMAC).
 */
const signedAxios = axios.create({
  baseURL: CONFIG_SERVICE_URL,
  timeout: 10000,
});
 
signedAxios.interceptors.request.use((config) => {
  config.headers = addInternalKey(config.headers || {}, SERVICE_NAME);
  return config;
});
 
module.exports = { signedAxios, CONFIG_SERVICE_URL };