@data-forge-services/core
Version:
Core component library for Data Forge services including location, timezone, and more.
30 lines (26 loc) • 1.26 kB
JavaScript
// src/axios.js
import axios from "axios";
// This will import the configuration file generated by setup.mjs
// or the fallback version from your repository if setup.mjs hasn't run or failed.
import configFromFile from "./location-selector/services.config.js";
const api = axios.create();
// Configure the Axios instance using the details from services.config.js
// This assumes setup.mjs writes a config for 'locationSelector'.
// If other services need different tokens/endpoints, this setup or setup.mjs needs adjustment.
if (
configFromFile &&
configFromFile.locationSelector &&
configFromFile.locationSelector.token &&
configFromFile.locationSelector.endpoint
) {
api.defaults.baseURL = configFromFile.locationSelector.endpoint;
api.defaults.headers.common['Authorization'] = `Bearer ${configFromFile.locationSelector.token}`;
} else {
console.error(
"DataForgeVueComponents: API configuration is missing or incomplete. " +
"The postinstall script (setup.mjs) might have failed to fetch the API token, " +
"or the src/location-selector/services.config.js file is not correctly populated. " +
"Components relying on API calls may not function correctly."
);
}
export default api;