{"id":47929936,"url":"https://github.com/cnumr/ecoindex_bff","last_synced_at":"2026-04-07T16:02:16.889Z","repository":{"id":104271359,"uuid":"574559869","full_name":"cnumr/EcoIndex_BFF","owner":"cnumr","description":"Simple Back For Front project to interface with Ecoindex API and facilitate Badge status generation","archived":false,"fork":false,"pushed_at":"2026-02-24T13:34:11.000Z","size":126,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-24T16:44:54.706Z","etag":null,"topics":["ecoindex","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cnumr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-12-05T15:21:13.000Z","updated_at":"2026-02-24T13:33:44.000Z","dependencies_parsed_at":"2023-10-11T04:48:30.237Z","dependency_job_id":"8b9f235e-6f33-450e-aec0-7c46e6138fe7","html_url":"https://github.com/cnumr/EcoIndex_BFF","commit_stats":{"total_commits":53,"total_committers":5,"mean_commits":10.6,"dds":"0.18867924528301883","last_synced_commit":"b170002c0d5b193a588f9ef8d2609afa020a86ca"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/cnumr/EcoIndex_BFF","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnumr%2FEcoIndex_BFF","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnumr%2FEcoIndex_BFF/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnumr%2FEcoIndex_BFF/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnumr%2FEcoIndex_BFF/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cnumr","download_url":"https://codeload.github.com/cnumr/EcoIndex_BFF/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnumr%2FEcoIndex_BFF/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31391078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T04:26:24.776Z","status":"ssl_error","status_checked_at":"2026-04-04T04:23:34.147Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecoindex","golang"],"created_at":"2026-04-04T07:14:55.981Z","updated_at":"2026-04-04T07:14:57.116Z","avatar_url":"https://github.com/cnumr.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ecoindex Back For Front\n\nThis project aims to provide a simple back for front for [ecoindex API](https://github.com/cnumr/ecoindex_api) project. It is mainly used by the [ecoindex browser plugin](https://github.com/vvatelot/ecoindex-browser-plugin).\n\nIt offers a way to retrieve easily the latest results for a given page, and also for the current website\n\nIt is built in Golang and Fiber to provide great performance and be as light as possible\n\n## 🛠️ Tech Stack\n\n- [Docker](https://www.docker.com/)\n- [Docker Compose v2](https://docs.docker.com/compose/compose-v2/)\n- [Golang](https://go.dev/)\n- [Fiber](https://gofiber.io/)\n- [Air](https://github.com/cosmtrek/air) (live reload)\n- [Redis](https://redis.io/) for caching\n\n## 🛠️ Install Dependencies\n\n```bash\ngo mod download\n```\n\n### Using mise (optional)\n\nIf you use [`mise`](https://github.com/jdx/mise) to manage your development tools, this repository ships a `mise.toml` that pins the required tools:\n\n- `go` (Go toolchain)\n- `air` (live reload for development)\n\nFrom the project root, you can install and activate the tools defined in `mise.toml` with:\n\n```bash\nmise install\n```\n\nAfter that, you can run the usual commands (`go test ./...`, `air`, etc.) using the versions managed by `mise`.\n\n## 🧑🏻‍💻 Usage\n\nTo start the project, you first need configure your `.env` file and provide the url of the ecoindex API you want to reach by setting the environment variable `API_URL`. Default is set to `https://ecoindex.p.rapidapi.com`.\n\n```bash\ncp .env.dist .env\n```\n\nIf you use production API url, you have to [request an API key](https://rapidapi.com/cnumr-cnumr-default/api/ecoindex/pricing) on RapidAPI platform. Once you get your API Key, you can set the env variable `API_KEY`\n\n```bash\nAPI_URL=https://ecoindex.p.rapidapi.com        # Or your own server url\nAPI_KEY=your-generated-api-key                     # Optional if not production server\n\n# You can also specify your application listening port (default is 3001)\nAPP_PORT=1337\n```\n\nYou need to launch a local redis server. The simpliest way to do so is to use a docker image of redis:\n\n```bash\ndocker run -d -p 6379:6379 redis\n```\n\nThen you can launch your project simply using air command:\n\n```bash\nair\n```\n\nYou can also use docker compose to launch the project:\n\n```bash\ncp docker-compose.yml.dist docker-compose.yml\ndocker-compose up -d --build \u0026\u0026 docker-compose logs -f\n```\n\n\u003e You can now reach your Back For Front instance on [http://localhost:3001](http://localhost:3001) (regarding the `APP_PORT` you defined...)\n\n### 🔄 Update Ecoindex reference\n\nThis project embeds the official [Ecoindex reference JSON](https://raw.githubusercontent.com/cnumr/ecoindex_reference/refs/heads/main/ecoindex_reference.json) to map grades (A–G) to colors.\n\nTo refresh the local copy used by the service, run:\n\n```bash\n./.github/update_ecoindex_reference.sh\n```\n\nThis script will download the latest `ecoindex_reference.json` from the Ecoindex reference repository into `services/ecoindex_reference.json`, which is then embedded in the Go binary.\n\nA GitHub Action (`.github/workflows/check-ecoindex-reference.yml`) checks on each pull request to `main` that `services/ecoindex_reference.json` is strictly identical to the remote reference; if the check fails, run the script above and commit the updated file.\n\n## 🔧 Configuration\n\n### Environment variables\n\n| Name            | Description                                                                                                                     | Default value                                        |\n|-----------------|---------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------|\n| `API_URL`       | The url of the ecoindex API you want to reach                                                                                   | `\"https://ecoindex.p.rapidapi.com\"`                  |\n| `API_KEY`       | The API key you want to use to reach the ecoindex API (if production server)                                                    | `\"\"`                                                 |\n| `APP_PORT`      | The port on which the application will listen                                                                                   | `3001`                                               |\n| `APP_URL`       | The url of the application                                                                                                      | `\"http://localhost:3001\"`                            |\n| `BADGE_VERSION` | The version of the badge you want to use (comes from [Ecindex badge project](https://github.com/cnumr/ecoindex_badge/releases)) | `\"v1\"`                                               |\n| `CACHE_DSN`     | The DSN of the Redis cache                                                                                                      | `\"localhost:6379\"`                                   |\n| `CACHE_ENABLED` | If you want to serve API results from cache                                                                                     | `true`                                               |\n| `CACHE_TTL`     | The time to live of the cache (in seconds)                                                                                      | `604800` (1 week)                                    |\n| `CDN_URL`       | The base url of the CDN where the badge is hosted                                                                               | `\"https://cdn.jsdelivr.net/gh/cnumr/ecoindex_badge\"` |\n| `ECOINDEX_URL`  | The url of the ecoindex website                                                                                                 | `\"https://www.ecoindex.fr\"`                          |\n| `ENV`           | The environment in which the application is running (in dev mode, enables logging)                                              | `dev`                                                |\n\n### About caching\n\nThe application uses a Redis cache to store the results of the API calls (only for `/ecoindexes*` endpoints). It is enabled by default, but you can disable it by setting the `CACHE_ENABLED` environment variable to `false`.\n\nThe cache is set to expire after 1 week (604800 seconds). You can change this value by setting the `CACHE_TTL` environment variable.\n\nEndpoints `/badge`, `/redirect` and `/api/results` provide a `refresh` parameter to force the cache to be refreshed. Those endpoints also add `cache-control` header set to `public, max-age=604800` (1 week) to allow the browser to cache the response.\n\n## ➤ API Reference\n\n### Get latest results info\n\n```http\nGET /api/results/?url=https://www.mywebsite.com/my-page/\n```\n\n#### Get latest results parameters\n\n| Name      | Type      | Located in | Description                                                                                  |\n|-----------|-----------|------------|----------------------------------------------------------------------------------------------|\n| `url`     | `string`  | query      | **Required**. This is the url of the page from which you want to retrieve the latest results |\n| `refresh` | `boolean` | query      | **Optional**. If set to true, the cache will be refreshed                                    |\n\n#### Get latest results responses\n\n| Code | Description                      | Model                                         |\n|------|----------------------------------|-----------------------------------------------|\n| 200  | There are results in the DB      | [LatestResultResponse](#latestresultresponse) |\n| 400  | The url is not valid             | String                                        |\n| 404  | There is no result for this page | [LatestResultResponse](#latestresultresponse) |\n\n### Add a new analysis to the tasks queue\n\nThis is an alias of the [ecoindex API](https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/cnumr/ecoindex_api/main/docs/openapi.json#tag/Tasks/operation/Add_new_ecoindex_analysis_task_to_the_waiting_queue_v1_tasks_ecoindexes_post) Create a new task endpoint\n\n```http\nPOST /api/tasks\n{\n    \"url\": \"https://www.mywebsite.com/my-page/\",\n    \"width\": 1920,\n    \"height\": 1080\n}\n```\n\n### Get the result of a task\n\nThis is an alias of the [ecoindex API](https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/cnumr/ecoindex_api/main/docs/openapi.json#tag/Tasks/operation/Get_ecoindex_analysis_task_by_id_v1_tasks_ecoindexes__id__get) Get the result of a task endpoint\n\n```http\nGET /api/tasks/a7c3d264-62c6-4f45-b1db-51d7db31d085\n```\n\n### Get the screenshot of a ecoindex result\n\nThis is an alias of the [ecoindex API](https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/cnumr/ecoindex_api/main/docs/openapi.json#tag/Ecoindex/operation/Get_screenshot__version__ecoindexes__id__screenshot_get) Get screenshot of a ecoindex result endpoint\n\n```http\nGET /api/screenshot/a7c3d264-62c6-4f45-b1db-51d7db31d085\n```\n\n### Get Api Health\n\n```http\nGET /health\n```\n\n#### Get health response\n\n| Code | Description         | Model  |\n|------|---------------------|--------|\n| 200  | `OK` API is healthy | String |\n\n### Get Ecoindex badge\n\n```http\nGET /badge/?url=https://www.mywebsite.com/my-page/\n```\n\n#### Get badge parameters\n\n| Name      | Type      | Located in | Description                                                                                  |\n|-----------|-----------|------------|----------------------------------------------------------------------------------------------|\n| `url`     | `string`  | query      | **Required**. This is the url of the page from which you want to retrieve the latest results |\n| `refresh` | `boolean` | query      | **Optional**. If set to true, the cache will be refreshed                                    |\n| `theme`   | `string`  | query      | **Optional**. `light` / `dark`. If not set, defaults to `light`                              |\n\n#### Get badge responses\n\n| Code | Description                            | Model  |\n|------|----------------------------------------|--------|\n| 200  | Badge of the result (format `svg/xml`) | String |\n| 400  | The url is not valid                   | String |\n\n### Redirect to ecoindex result page\n\n```http\nGET /redirect/?url=https://www.mywebsite.com/my-page/\n```\n\n#### Get redirect parameters\n\n| Name      | Type      | Located in | Description                                                                                  |\n|-----------|-----------|------------|----------------------------------------------------------------------------------------------|\n| `url`     | `string`  | query      | **Required**. This is the url of the page from which you want to retrieve the latest results |\n| `refresh` | `boolean` | query      | **Optional**. If set to true, the cache will be refreshed                                    |\n\n#### Get redirect responses\n\n| Code | Description                 | Model  |\n|------|-----------------------------|--------|\n| 303  | Redirect to the result page | String |\n| 400  | The url is not valid        | String |\n\n### Models\n\n#### Result\n\n| Name       | Type     | Description                               |\n|------------|----------|-------------------------------------------|\n| `date`     | `string` | Date of the result                        |\n| `grade`    | `string` | Ecoindex result grade                     |\n| `id`       | `string` | Result UUID                               |\n| `nodes`    | `int`    | Number of nodes in the DOM of the webpage |\n| `requests` | `int`    | Number of requests made by the webpage    |\n| `score`    | `int`    | Ecoindex result score                     |\n| `size`     | `int`    | Size of the webpage                       |\n| `url`      | `string` | Page URL                                  |\n\n#### LatestResultResponse\n\n| Name            | Type                | Description                                       |\n|-----------------|---------------------|---------------------------------------------------|\n| `count`         | `int`               | Number of total results existing for this website |\n| `latest-result` | [Result](#result)   | Latest result for this exact webpage              |\n| `older-results` | [Result](#result)[] | Older results for the same webpage                |\n| `other-results` | [Result](#result)[] | Other results tor this website                    |\n\n## [License](LICENSE)\n\n## [Contributing](CONTRIBUTING.md)\n\n## [Code of conduct](CODE_OF_CONDUCT.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnumr%2Fecoindex_bff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcnumr%2Fecoindex_bff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnumr%2Fecoindex_bff/lists"}