2
2
* The axios Cloud instance should not be used.
3
3
*/
4
4
import os from 'os'
5
-
6
5
import followRedirects from 'follow-redirects'
7
6
import axios , { AxiosInstance } from 'axios'
8
7
import pkg from '@packages/root'
@@ -13,18 +12,52 @@ import { installErrorTransform } from './axios_middleware/transform_error'
13
12
import { installLogging } from './axios_middleware/logging'
14
13
import { installEncryption } from './axios_middleware/encryption'
15
14
15
+ export interface CreateCloudRequestOptions {
16
+ /**
17
+ * The baseURL for all requests for this Cloud Request instance
18
+ */
19
+ baseURL ?: string
20
+ /**
21
+ * Additional headers for the Cloud Request
22
+ */
23
+ addditionalHeaders ?: Record < string , string >
24
+ /**
25
+ * Whether to include e2e encryption for requests:
26
+ * true = encrypt request, decrypt response if x-cypress-encrypted signature is set
27
+ * always = encrypt request, always decrypt response
28
+ * signed = send version in x-cypress-signature, check response's x-cypress-signature
29
+ * false = no encryption
30
+ *
31
+ * @default false
32
+ */
33
+ enableEncryption ?: 'always' | 'signed' | true | false
34
+ /**
35
+ * Whether to include the default logging middleware
36
+ * @default true
37
+ */
38
+ enableLogging ?: boolean
39
+ /**
40
+ * Whether to include the default error transformation
41
+ * @default true
42
+ */
43
+ enableErrorTransform ?: boolean
44
+ }
45
+
16
46
// Allows us to create customized Cloud Request instances w/ different baseURL & encryption configuration
17
- export const createCloudRequest = ( options : { baseURL ?: string , encrypt ?: 'always' | 'signed' | true } = { } ) : AxiosInstance => {
47
+ export const createCloudRequest = ( options : CreateCloudRequestOptions = { } ) : AxiosInstance => {
18
48
const cfgKey = process . env . CYPRESS_CONFIG_ENV || process . env . CYPRESS_INTERNAL_ENV || 'development'
49
+ const { baseURL = app_config [ cfgKey ] . api_url , enableEncryption = false , enableLogging = true , enableErrorTransform = true } = options
19
50
20
51
const instance = axios . create ( {
21
- baseURL : options . baseURL ?? app_config [ cfgKey ] . api_url ,
52
+ baseURL,
22
53
httpAgent : agent ,
23
54
httpsAgent : agent ,
55
+ allowAbsoluteUrls : false ,
24
56
headers : {
25
57
'x-os-name' : os . platform ( ) ,
26
58
'x-cypress-version' : pkg . version ,
27
59
'User-Agent' : `cypress/${ pkg . version } ` ,
60
+ ...options . addditionalHeaders ,
28
61
} ,
29
62
transport : {
30
63
// https://github.com/axios/axios/issues/6313#issue-2198831362
@@ -44,12 +77,17 @@ export const createCloudRequest = (options: { baseURL?: string, encrypt?: 'alway
44
77
} ,
45
78
} )
46
79
47
- if ( options . encrypt ) {
48
- installEncryption ( instance , options . encrypt )
80
+ if ( enableEncryption ) {
81
+ installEncryption ( instance , enableEncryption )
49
82
}
50
83
51
- installLogging ( instance )
52
- installErrorTransform ( instance )
84
+ if ( enableLogging ) {
85
+ installLogging ( instance )
86
+ }
87
+
88
+ if ( enableErrorTransform ) {
89
+ installErrorTransform ( instance )
90
+ }
53
91
54
92
return instance
55
93
}
0 commit comments