-
Notifications
You must be signed in to change notification settings - Fork 4
feat(client): add HTTPS agent configuration for secure requests #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,16 +1,22 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| import axios, { AxiosInstance } from 'axios'; | ||||||||||||||||||||||||||||||||||||||||||||
| import https from 'https'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { env } from '../env.js'; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| export class FacturaScriptsClient { | ||||||||||||||||||||||||||||||||||||||||||||
| private client: AxiosInstance; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| constructor() { | ||||||||||||||||||||||||||||||||||||||||||||
| const httpsAgent = process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0' | ||||||||||||||||||||||||||||||||||||||||||||
| ? new https.Agent({ rejectUnauthorized: false }) | ||||||||||||||||||||||||||||||||||||||||||||
| : undefined; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| this.client = axios.create({ | ||||||||||||||||||||||||||||||||||||||||||||
| baseURL: `${env.FS_BASE_URL}/api/${env.FS_API_VERSION}`, | ||||||||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||||||||
| 'token': env.FS_API_TOKEN, | ||||||||||||||||||||||||||||||||||||||||||||
| 'Content-Type': 'application/json', | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| httpsAgent, | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
8
to
+19
|
||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
13
to
20
|
||||||||||||||||||||||||||||||||||||||||||||
| this.client = axios.create({ | |
| baseURL: `${env.FS_BASE_URL}/api/${env.FS_API_VERSION}`, | |
| headers: { | |
| 'token': env.FS_API_TOKEN, | |
| 'Content-Type': 'application/json', | |
| }, | |
| httpsAgent, | |
| }); | |
| const axiosConfig = { | |
| baseURL: `${env.FS_BASE_URL}/api/${env.FS_API_VERSION}`, | |
| headers: { | |
| 'token': env.FS_API_TOKEN, | |
| 'Content-Type': 'application/json', | |
| }, | |
| }; | |
| if (httpsAgent) { | |
| (axiosConfig as any).httpsAgent = httpsAgent; | |
| } | |
| this.client = axios.create(axiosConfig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
NODE_TLS_REJECT_UNAUTHORIZED === '0'to disable certificate verification makes it easy to accidentally run with TLS validation turned off (MITM risk). Consider using an explicit, library-scoped env var (validated inenv.ts) and/or restricting insecure mode to localhost/non-production, and emitting a clear warning when it’s enabled.