Skip to content

Commit fa73f44

Browse files
authored
feat: allow users to opt out of CORS proxy (#11)
1 parent 8ef1f37 commit fa73f44

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ The extension can be configured through JSON in user, organization or global set
4747
// CORS headers are necessary for the extension to fetch data, but Sonarqube does not send them by default.
4848
// Here you can customize the URL to an HTTP proxy that adds CORS headers.
4949
// By default Sourcegraph's CORS proxy is used.
50+
// Set this to `null` to opt out of using a CORS proxy.
5051
"sonarqube.corsAnywhereUrl": "https://cors-anywhere.sgdev.org"
5152
}
5253
```

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@
6363
"type": "string"
6464
},
6565
"sonarqube.corsAnywhereUrl": {
66-
"description": "The URL to a CORS proxy.",
67-
"type": "string",
66+
"description": "The URL to a CORS proxy. Set to null to opt out of using a CORS proxy.",
67+
"type": [
68+
"string",
69+
"null"
70+
],
6871
"default": "https://cors-anywhere.sgdev.org"
6972
},
7073
"sonarqube.repositoryNamePattern": {

src/sonarqube.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface Configuration {
2222
'sonarqube.showIssuesOnCodeViews'?: boolean
2323
'sonarqube.instanceUrl'?: string
2424
'sonarqube.apiToken'?: string
25-
'sonarqube.corsAnywhereUrl'?: string
25+
'sonarqube.corsAnywhereUrl'?: string | null
2626
'sonarqube.organizationPattern'?: string
2727
'sonarqube.organizationKeyTemplate'?: string
2828
'sonarqube.projectKeyTemplate'?: string
@@ -45,13 +45,20 @@ export function activate(context: sourcegraph.ExtensionContext): void {
4545
if (config['sonarqube.showIssuesOnCodeViews'] === false) {
4646
return { editor, issues: [] as Issue[], errorMessage: null }
4747
}
48-
const corsAnyWhereUrl = new URL(
49-
config['sonarqube.corsAnywhereUrl'] || 'https://cors-anywhere.sgdev.org'
50-
)
48+
const corsAnyWhereUrl =
49+
config['sonarqube.corsAnywhereUrl'] === null
50+
? null
51+
: new URL(config['sonarqube.corsAnywhereUrl'] || 'https://cors-anywhere.sgdev.org')
52+
5153
const sonarqubeUrl = new URL(config['sonarqube.instanceUrl'] || 'https://sonarcloud.io/')
5254
const apiOptions: ApiOptions = {
5355
sonarqubeApiUrl: new URL(
54-
`${corsAnyWhereUrl.href.replace(/\/$/, '')}/${sonarqubeUrl.href.replace(/\/$/, '')}/`
56+
corsAnyWhereUrl
57+
? `${corsAnyWhereUrl.href.replace(/\/$/, '')}/${sonarqubeUrl.href.replace(
58+
/\/$/,
59+
''
60+
)}/`
61+
: `${sonarqubeUrl.href.replace(/\/$/, '')}/`
5562
),
5663
apiToken: config['sonarqube.apiToken'],
5764
}

0 commit comments

Comments
 (0)