diff --git a/README.md b/README.md index 4fb9b79..7dd9297 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ To follow these steps, ensure that your environment is configured to run Node.js - `REDIS_URL`: connection string for redis - `MONGO_URL`: connection string for mongodb - `RAIL_URL`: url of the rail api +- `RAIL_API_KEY`: api key for the rail api +- `PROXY_URL`: url of the proxy service - `APPLE_BUNDLE_ID`: bundle id of the iOS app to send notifications to - `APPLE_TEAM_ID`: team id for the developer account associated with the iOS app - `APPLE_KEY_ID`: apple notifications key id diff --git a/package.json b/package.json index 3efb733..937c499 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "express": "^4.18.2", "express-rate-limit": "^6.7.0", "firebase-admin": "^11.7.0", + "https-proxy-agent": "^7.0.6", "lodash": "^4.17.21", "node-schedule": "^2.1.1", "redis": "^4.6.5", diff --git a/src/data/config.ts b/src/data/config.ts index a840727..6668a54 100644 --- a/src/data/config.ts +++ b/src/data/config.ts @@ -9,6 +9,8 @@ export const port = process.env.PORT || 3000 export const redisUrl = process.env.REDIS_URL as string export const mongoUrl = process.env.MONGO_URL as string export const railUrl = process.env.RAIL_URL as string +export const railApiKey = process.env.RAIL_API_KEY as string +export const proxyUrl = process.env.PROXY_URL as string export const appleBundleId = process.env.APPLE_BUNDLE_ID as string export const appleTeamId = process.env.APPLE_TEAM_ID as string export const appleKeyId = process.env.APPLE_KEY_ID as string diff --git a/src/requests/rail-api.ts b/src/requests/rail-api.ts index fca49ad..f088264 100644 --- a/src/requests/rail-api.ts +++ b/src/requests/rail-api.ts @@ -1,8 +1,11 @@ +process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" + import http from "http" import axiosRetry from "axios-retry" import axios, { AxiosInstance } from "axios" +import { HttpsProxyAgent } from "https-proxy-agent" -import { railUrl } from "../data/config" +import { railUrl, proxyUrl, railApiKey } from "../data/config" http.globalAgent.maxSockets = 100 @@ -13,9 +16,10 @@ export class RailApi { this.axiosInstance = axios.create({ baseURL: railUrl, timeout: 30000, + httpsAgent: proxyUrl && new HttpsProxyAgent(proxyUrl), headers: { Accept: "application/json", - "Ocp-Apim-Subscription-Key": "4b0d355121fe4e0bb3d86e902efe9f20", + "Ocp-Apim-Subscription-Key": railApiKey, }, }) diff --git a/yarn.lock b/yarn.lock index 7fdc5a1..08cf4eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1144,6 +1144,11 @@ agent-base@6: dependencies: debug "4" +agent-base@^7.1.2: + version "7.1.4" + resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-7.1.4.tgz#e3cd76d4c548ee895d3c3fd8dc1f6c5b9032e7a8" + integrity sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ== + ansi-escapes@^4.2.1: version "4.3.2" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-4.3.2.tgz#6b2291d1db7d98b6521d5f1efa42d0f3a9feb65e" @@ -2322,6 +2327,14 @@ https-proxy-agent@^5.0.0: agent-base "6" debug "4" +https-proxy-agent@^7.0.6: + version "7.0.6" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz#da8dfeac7da130b05c2ba4b59c9b6cd66611a6b9" + integrity sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw== + dependencies: + agent-base "^7.1.2" + debug "4" + human-signals@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"