import axios from 'axios'
import MessageWebsocketService from '@/widgets/messages/services/MessageWebsocketService'

export const httpClient = axios.create()

httpClient.defaults.withCredentials = true
httpClient.defaults.baseURL = process.env.MESSAGES_API_URL

httpClient.interceptors.request.use(
  function(config) {
    config.headers['X-Site'] = process.env.PROJECT_NAME

    if (MessageWebsocketService.client) {
      config.headers['X-Socket-Id'] = MessageWebsocketService.client.socketId()
    }

    return config
  },
  function(error) {
    return Promise.reject(error)
  }
)
