Skip to content

Commit

Permalink
Feat/env variables (#183)
Browse files Browse the repository at this point in the history
* Get api settings from config (or environment variables)

* Remove debugger

* format code

---------

Co-authored-by: Vincent Vatelot <vincent.vatelot@ik.me>
  • Loading branch information
yaaax and vvatelot authored Jan 8, 2024
1 parent addaf5a commit 90d9c02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 6 additions & 6 deletions assets/js/services/ApiService.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import ky from "ky";
import params from "@params";

class ApiService {
#controller = null;

// TODO import data with build : https://gohugo.io/hugo-pipes/js/#:~:text=params%20%5Bmap%20or,New%20in%20v0.78.0

// TODO set from .env ?
#baseURL = "https://api.ecoindex.fr/v1/";
// Params imported from Hugo config params
// (they can be defined through environment variables)
#apiKey = params.api.key;
#baseURL = params.api.baseurl;
#host = params.api.host;
#browserWidth = 1920;
#browserHeight = 1080;

Expand Down Expand Up @@ -85,9 +87,7 @@ class ApiService {
async #fetchApi(slug, options) {
this.abortAnalysis();
const controller = (this.#controller = new AbortController());

const { signal } = controller;

const response = await ky(slug, {
...options,
prefixUrl: this.#baseURL,
Expand Down
5 changes: 5 additions & 0 deletions config/_default/params.toml
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
themeColor = "#007e5f"

[api]
key = "3037e7e96fmsh12bedced9f019f8p1cd804jsn4967070f8bda"
baseurl = "https://ecoindex.p.rapidapi.com/v1/"
host = "ecoindex.p.rapidapi.com"

0 comments on commit 90d9c02

Please sign in to comment.