-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated from got to node-fetch package
- Loading branch information
1 parent
f55c61f
commit a3c86a6
Showing
13 changed files
with
100 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,37 @@ | ||
MONGODB_URL=mongodb://127.0.0.1:27017 | ||
MONGODB_PORT=27017 | ||
# Mongo DB | ||
MONGODB_URL=mongodb://127.0.0.1:27017 # Not used for deployment with Docker Compose | ||
MONGODB_PORT=27017 # Used only for deployment with Docker Compose | ||
MONGODB_DBNAME=ban | ||
|
||
REDIS_URL=redis://127.0.0.1:6379 | ||
REDIS_PORT=6379 | ||
# Redis | ||
REDIS_URL=redis://127.0.0.1:6379 # Not used for deployment with Docker Compose | ||
REDIS_PORT=6379 # Used only for Docker Compose | ||
|
||
# APIs | ||
# API BAN | ||
BAN_API_URL=https://plateforme.adresse.data.gouv.fr | ||
BAN_API_AUTHORIZED_TOKENS= | ||
ADMIN_TOKEN= # Used for legacy routes | ||
BAN_API_AUTHORIZED_TOKENS= # Used for new ban-id api routes | ||
PORT=5000 | ||
|
||
# relative path from the "root" directory for all the following path variables : | ||
# API de dépôt | ||
API_DEPOT_URL=https://plateforme.adresse.data.gouv.fr/api-depot | ||
|
||
# API ID-Fix | ||
API_IDFIX_URL=https://plateforme.adresse.data.gouv.fr/api-idfix | ||
API_IDFIX_TOKEN= | ||
|
||
# Path to data files | ||
# Relative path from the "root" directory for all the following path variables : | ||
FANTOIR_PATH=data/fantoir.sqlite | ||
GAZETTEER_DB_PATH=data/gazetteer.sqlite | ||
MAJIC_PATH=/data/majic.sqlite | ||
CONTOURS_DATA_PATH=data/communes-50m.sqlite | ||
COMMUNES_LOCAUX_ADRESSES_DATA_PATH=data/communes-locaux-adresses.json | ||
|
||
DEPARTEMENTS= | ||
|
||
# Others | ||
DEPARTEMENTS= # Comma separated list of departements for dev only | ||
JOB_STATUS_LIMIT_DURATION='90d' # Duration max of job status in database | ||
MAX_CONCURRENT_WORKERS=1 | ||
|
||
DATAGOUV_API_KEY= | ||
|
||
API_DEPOT_URL=https://plateforme.adresse.data.gouv.fr/api-depot | ||
|
||
API_IDFIX_URL=https://plateforme.adresse.data.gouv.fr/api-idfix | ||
API_IDFIX_TOKEN= | ||
|
||
ADMIN_TOKEN= | ||
|
||
JOB_STATUS_LIMIT_DURATION='90d' | ||
|
||
PORT=5000 | ||
PROXY_URL= # To use only if you are behind a proxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const fetch = require('node-fetch') | ||
const HttpsProxyAgent = require('https-proxy-agent') | ||
|
||
const PROXY_URL = process.env.PROXY_URL || '' | ||
|
||
class HTTPResponseError extends Error { | ||
constructor(response) { | ||
super(`HTTP Error Response: ${response.status} ${response.statusText}`) | ||
this.response = response | ||
} | ||
} | ||
|
||
const fetchWithProxy = async (url, options) => { | ||
try { | ||
let response | ||
if (PROXY_URL) { | ||
const agent = new HttpsProxyAgent(PROXY_URL) | ||
response = await fetch(url, {...options, agent}) | ||
} else { | ||
response = await fetch(url, options) | ||
} | ||
|
||
if (response.status >= 400) { | ||
throw new HTTPResponseError(response) | ||
} | ||
|
||
return response | ||
} catch (error) { | ||
// Handle any network or other errors | ||
console.error(`Request failed : ${error.message}`) | ||
throw error | ||
} | ||
} | ||
|
||
module.exports = fetchWithProxy |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.