Skip to content

Commit f02b569

Browse files
committed
feat: allow for providing an alternative domain for the proxy
Have the service report back the proxyURL for each project, rather than being embedded inside the frontend bundle. Concequence is duplicating some data but very minor and allows for us to serve different projects from different proxies in the future. Removed unused vite env var, added method to pull service's current path and substitute in the http proxy port. Works for local dev, should maintain current behaviour. Custom domain can be applied via optional config. New config value added to the config schema. Config schema documentation has been regenerated (including some other absent items).
1 parent cae6d3a commit f02b569

File tree

9 files changed

+83
-34
lines changed

9 files changed

+83
-34
lines changed

.env.development

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
VITE_API_URI=http://localhost:8080
2-
VITE_SERVER_URI=http://localhost:8000

config.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"description": "Customisable questions to add to attestation form",
2121
"type": "object"
2222
},
23+
"domains": {
24+
"description": "Provide domains to use alternative to the defaults",
25+
"type": "object"
26+
},
2327
"privateOrganizations": {
2428
"description": "Pattern searches for listed private organizations are disabled",
2529
"type": "array"

proxy.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
}
9393
]
9494
},
95+
"domains": {},
9596
"privateOrganizations": [],
9697
"urlShortener": "",
9798
"contactEmail": "",

src/config/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ let _privateOrganizations = defaultSettings.privateOrganizations;
2424
let _urlShortener = defaultSettings.urlShortener;
2525
let _contactEmail = defaultSettings.contactEmail;
2626
let _csrfProtection = defaultSettings.csrfProtection;
27+
let _domains = defaultSettings.domains;
2728

2829
// Get configured proxy URL
2930
const getProxyUrl = () => {
@@ -189,6 +190,13 @@ const getSSLCertPath = () => {
189190
return _sslCertPath;
190191
};
191192

193+
const getDomains = () => {
194+
if (_userSettings && _userSettings.domains) {
195+
_domains = _userSettings.domains;
196+
}
197+
return _domains;
198+
};
199+
192200
exports.getAPIs = getAPIs;
193201
exports.getProxyUrl = getProxyUrl;
194202
exports.getAuthorisedList = getAuthorisedList;
@@ -207,3 +215,4 @@ exports.getCSRFProtection = getCSRFProtection;
207215
exports.getPlugins = getPlugins;
208216
exports.getSSLKeyPath = getSSLKeyPath;
209217
exports.getSSLCertPath = getSSLCertPath;
218+
exports.getDomains = getDomains;

src/service/proxyURL.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { GIT_PROXY_SERVER_PORT: PROXY_HTTP_PORT, GIT_PROXY_UI_PORT: UI_PORT } =
2+
require('../config/env').Vars;
3+
const config = require('../config');
4+
5+
module.exports = {
6+
getProxyURL: (req) => {
7+
const defaultURL = `${req.protocol}://${req.headers.host}`.replace(
8+
`:${UI_PORT}`,
9+
`:${PROXY_HTTP_PORT}`,
10+
);
11+
return config.getDomains().proxy ?? defaultURL;
12+
},
13+
};

src/service/routes/repo.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const express = require('express');
22
const router = new express.Router();
33
const db = require('../../db');
4+
const { getProxyURL } = require('../proxyURL');
45

56
router.get('/', async (req, res) => {
7+
const proxyURL = getProxyURL(req);
68
const query = {
79
type: 'push',
810
};
@@ -18,12 +20,15 @@ router.get('/', async (req, res) => {
1820
query[k] = v;
1921
}
2022

21-
res.send(await db.getRepos(query));
23+
const qd = await db.getRepos(query);
24+
res.send(qd.map((d) => ({ ...d, proxyURL })));
2225
});
2326

2427
router.get('/:name', async (req, res) => {
28+
const proxyURL = getProxyURL(req);
2529
const name = req.params.name;
26-
res.send(await db.getRepo(name));
30+
const qd = await db.getRepo(name);
31+
res.send({ ...qd, proxyURL });
2732
});
2833

2934
router.patch('/:name/user/push', async (req, res) => {

src/ui/views/RepoDetails/RepoDetails.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ export default function RepoDetails() {
5959
if (isLoading) return <div>Loading...</div>;
6060
if (isError) return <div>Something went wrong ...</div>;
6161

62-
const { project: org, name } = data || {};
63-
const cloneURL = `${import.meta.env.VITE_SERVER_URI}/${org}/${name}.git`;
62+
const { project: org, name, proxyURL } = data || {};
63+
const cloneURL = `${proxyURL}/${org}/${name}.git`;
6464

6565
return (
6666
<GridContainer>

src/ui/views/RepoList/Components/RepoOverview.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,8 @@ export default function Repositories(props) {
584584
});
585585
};
586586

587-
const { project: org, name } = props?.data || {};
588-
const cloneURL = `${window.location.origin.toString()}/${org}/${name}.git`;
587+
const { project: org, name, proxyURL } = props?.data || {};
588+
const cloneURL = `${proxyURL}/${org}/${name}.git`;
589589

590590
return (
591591
<TableRow>

website/docs/configuration/reference.mdx

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,25 @@ description: JSON schema reference documentation for GitProxy
116116

117117
<details>
118118
<summary>
119-
<strong> <a name="privateOrganizations"></a>7. [Optional] Property GitProxy configuration file > privateOrganizations</strong>
119+
<strong> <a name="domains"></a>7. [Optional] Property GitProxy configuration file > domains</strong>
120+
121+
</summary>
122+
<blockquote>
123+
124+
| | |
125+
| ------------------------- | ------------------------------------------------------------------------- |
126+
| **Type** | `object` |
127+
| **Required** | No |
128+
| **Additional properties** | [[Any type: allowed]](# "Additional Properties of any type are allowed.") |
129+
130+
**Description:** Provide domains to use alternative to the defaults
131+
132+
</blockquote>
133+
</details>
134+
135+
<details>
136+
<summary>
137+
<strong> <a name="privateOrganizations"></a>8. [Optional] Property GitProxy configuration file > privateOrganizations</strong>
120138

121139
</summary>
122140
<blockquote>
@@ -133,7 +151,7 @@ description: JSON schema reference documentation for GitProxy
133151

134152
<details>
135153
<summary>
136-
<strong> <a name="urlShortener"></a>8. [Optional] Property GitProxy configuration file > urlShortener</strong>
154+
<strong> <a name="urlShortener"></a>9. [Optional] Property GitProxy configuration file > urlShortener</strong>
137155

138156
</summary>
139157
<blockquote>
@@ -150,7 +168,7 @@ description: JSON schema reference documentation for GitProxy
150168

151169
<details>
152170
<summary>
153-
<strong> <a name="contactEmail"></a>9. [Optional] Property GitProxy configuration file > contactEmail</strong>
171+
<strong> <a name="contactEmail"></a>10. [Optional] Property GitProxy configuration file > contactEmail</strong>
154172

155173
</summary>
156174
<blockquote>
@@ -167,7 +185,7 @@ description: JSON schema reference documentation for GitProxy
167185

168186
<details>
169187
<summary>
170-
<strong> <a name="csrfProtection"></a>10. [Optional] Property GitProxy configuration file > csrfProtection</strong>
188+
<strong> <a name="csrfProtection"></a>11. [Optional] Property GitProxy configuration file > csrfProtection</strong>
171189

172190
</summary>
173191
<blockquote>
@@ -184,7 +202,7 @@ description: JSON schema reference documentation for GitProxy
184202

185203
<details>
186204
<summary>
187-
<strong> <a name="plugins"></a>11. [Optional] Property GitProxy configuration file > plugins</strong>
205+
<strong> <a name="plugins"></a>12. [Optional] Property GitProxy configuration file > plugins</strong>
188206

189207
</summary>
190208
<blockquote>
@@ -200,7 +218,7 @@ description: JSON schema reference documentation for GitProxy
200218
| ------------------------------- | ----------- |
201219
| [plugins items](#plugins_items) | - |
202220

203-
### <a name="autogenerated_heading_2"></a>11.1. GitProxy configuration file > plugins > plugins items
221+
### <a name="autogenerated_heading_2"></a>12.1. GitProxy configuration file > plugins > plugins items
204222

205223
| | |
206224
| ------------ | -------- |
@@ -212,7 +230,7 @@ description: JSON schema reference documentation for GitProxy
212230

213231
<details>
214232
<summary>
215-
<strong> <a name="authorisedList"></a>12. [Optional] Property GitProxy configuration file > authorisedList</strong>
233+
<strong> <a name="authorisedList"></a>13. [Optional] Property GitProxy configuration file > authorisedList</strong>
216234

217235
</summary>
218236
<blockquote>
@@ -228,7 +246,7 @@ description: JSON schema reference documentation for GitProxy
228246
| --------------------------------------- | ----------- |
229247
| [authorisedRepo](#authorisedList_items) | - |
230248

231-
### <a name="autogenerated_heading_3"></a>12.1. GitProxy configuration file > authorisedList > authorisedRepo
249+
### <a name="autogenerated_heading_3"></a>13.1. GitProxy configuration file > authorisedList > authorisedRepo
232250

233251
| | |
234252
| ------------------------- | ------------------------------------------------------------------------- |
@@ -239,7 +257,7 @@ description: JSON schema reference documentation for GitProxy
239257

240258
<details>
241259
<summary>
242-
<strong> <a name="authorisedList_items_project"></a>12.1.1. [Required] Property GitProxy configuration file > authorisedList > authorisedList items > project</strong>
260+
<strong> <a name="authorisedList_items_project"></a>13.1.1. [Required] Property GitProxy configuration file > authorisedList > authorisedList items > project</strong>
243261

244262
</summary>
245263
<blockquote>
@@ -254,7 +272,7 @@ description: JSON schema reference documentation for GitProxy
254272

255273
<details>
256274
<summary>
257-
<strong> <a name="authorisedList_items_name"></a>12.1.2. [Required] Property GitProxy configuration file > authorisedList > authorisedList items > name</strong>
275+
<strong> <a name="authorisedList_items_name"></a>13.1.2. [Required] Property GitProxy configuration file > authorisedList > authorisedList items > name</strong>
258276

259277
</summary>
260278
<blockquote>
@@ -269,7 +287,7 @@ description: JSON schema reference documentation for GitProxy
269287

270288
<details>
271289
<summary>
272-
<strong> <a name="authorisedList_items_url"></a>12.1.3. [Required] Property GitProxy configuration file > authorisedList > authorisedList items > url</strong>
290+
<strong> <a name="authorisedList_items_url"></a>13.1.3. [Required] Property GitProxy configuration file > authorisedList > authorisedList items > url</strong>
273291

274292
</summary>
275293
<blockquote>
@@ -287,7 +305,7 @@ description: JSON schema reference documentation for GitProxy
287305

288306
<details>
289307
<summary>
290-
<strong> <a name="sink"></a>13. [Optional] Property GitProxy configuration file > sink</strong>
308+
<strong> <a name="sink"></a>14. [Optional] Property GitProxy configuration file > sink</strong>
291309

292310
</summary>
293311
<blockquote>
@@ -303,7 +321,7 @@ description: JSON schema reference documentation for GitProxy
303321
| ------------------------------- | ----------- |
304322
| [database](#sink_items) | - |
305323

306-
### <a name="autogenerated_heading_4"></a>13.1. GitProxy configuration file > sink > database
324+
### <a name="autogenerated_heading_4"></a>14.1. GitProxy configuration file > sink > database
307325

308326
| | |
309327
| ------------------------- | ------------------------------------------------------------------------- |
@@ -314,7 +332,7 @@ description: JSON schema reference documentation for GitProxy
314332

315333
<details>
316334
<summary>
317-
<strong> <a name="sink_items_type"></a>13.1.1. [Required] Property GitProxy configuration file > sink > sink items > type</strong>
335+
<strong> <a name="sink_items_type"></a>14.1.1. [Required] Property GitProxy configuration file > sink > sink items > type</strong>
318336

319337
</summary>
320338
<blockquote>
@@ -329,7 +347,7 @@ description: JSON schema reference documentation for GitProxy
329347

330348
<details>
331349
<summary>
332-
<strong> <a name="sink_items_enabled"></a>13.1.2. [Required] Property GitProxy configuration file > sink > sink items > enabled</strong>
350+
<strong> <a name="sink_items_enabled"></a>14.1.2. [Required] Property GitProxy configuration file > sink > sink items > enabled</strong>
333351

334352
</summary>
335353
<blockquote>
@@ -344,7 +362,7 @@ description: JSON schema reference documentation for GitProxy
344362

345363
<details>
346364
<summary>
347-
<strong> <a name="sink_items_connectionString"></a>13.1.3. [Optional] Property GitProxy configuration file > sink > sink items > connectionString</strong>
365+
<strong> <a name="sink_items_connectionString"></a>14.1.3. [Optional] Property GitProxy configuration file > sink > sink items > connectionString</strong>
348366

349367
</summary>
350368
<blockquote>
@@ -359,7 +377,7 @@ description: JSON schema reference documentation for GitProxy
359377

360378
<details>
361379
<summary>
362-
<strong> <a name="sink_items_options"></a>13.1.4. [Optional] Property GitProxy configuration file > sink > sink items > options</strong>
380+
<strong> <a name="sink_items_options"></a>14.1.4. [Optional] Property GitProxy configuration file > sink > sink items > options</strong>
363381

364382
</summary>
365383
<blockquote>
@@ -375,7 +393,7 @@ description: JSON schema reference documentation for GitProxy
375393

376394
<details>
377395
<summary>
378-
<strong> <a name="sink_items_params"></a>13.1.5. [Optional] Property GitProxy configuration file > sink > sink items > params</strong>
396+
<strong> <a name="sink_items_params"></a>14.1.5. [Optional] Property GitProxy configuration file > sink > sink items > params</strong>
379397

380398
</summary>
381399
<blockquote>
@@ -394,7 +412,7 @@ description: JSON schema reference documentation for GitProxy
394412

395413
<details>
396414
<summary>
397-
<strong> <a name="authentication"></a>14. [Optional] Property GitProxy configuration file > authentication</strong>
415+
<strong> <a name="authentication"></a>15. [Optional] Property GitProxy configuration file > authentication</strong>
398416

399417
</summary>
400418
<blockquote>
@@ -410,7 +428,7 @@ description: JSON schema reference documentation for GitProxy
410428
| --------------------------------------- | ----------- |
411429
| [authentication](#authentication_items) | - |
412430

413-
### <a name="autogenerated_heading_5"></a>14.1. GitProxy configuration file > authentication > authentication
431+
### <a name="autogenerated_heading_5"></a>15.1. GitProxy configuration file > authentication > authentication
414432

415433
| | |
416434
| ------------------------- | ------------------------------------------------------------------------- |
@@ -421,7 +439,7 @@ description: JSON schema reference documentation for GitProxy
421439

422440
<details>
423441
<summary>
424-
<strong> <a name="authentication_items_type"></a>14.1.1. [Required] Property GitProxy configuration file > authentication > authentication items > type</strong>
442+
<strong> <a name="authentication_items_type"></a>15.1.1. [Required] Property GitProxy configuration file > authentication > authentication items > type</strong>
425443

426444
</summary>
427445
<blockquote>
@@ -436,7 +454,7 @@ description: JSON schema reference documentation for GitProxy
436454

437455
<details>
438456
<summary>
439-
<strong> <a name="authentication_items_enabled"></a>14.1.2. [Required] Property GitProxy configuration file > authentication > authentication items > enabled</strong>
457+
<strong> <a name="authentication_items_enabled"></a>15.1.2. [Required] Property GitProxy configuration file > authentication > authentication items > enabled</strong>
440458

441459
</summary>
442460
<blockquote>
@@ -451,7 +469,7 @@ description: JSON schema reference documentation for GitProxy
451469

452470
<details>
453471
<summary>
454-
<strong> <a name="authentication_items_options"></a>14.1.3. [Optional] Property GitProxy configuration file > authentication > authentication items > options</strong>
472+
<strong> <a name="authentication_items_options"></a>15.1.3. [Optional] Property GitProxy configuration file > authentication > authentication items > options</strong>
455473

456474
</summary>
457475
<blockquote>
@@ -470,7 +488,7 @@ description: JSON schema reference documentation for GitProxy
470488

471489
<details>
472490
<summary>
473-
<strong> <a name="tempPassword"></a>15. [Optional] Property GitProxy configuration file > tempPassword</strong>
491+
<strong> <a name="tempPassword"></a>16. [Optional] Property GitProxy configuration file > tempPassword</strong>
474492

475493
</summary>
476494
<blockquote>
@@ -485,7 +503,7 @@ description: JSON schema reference documentation for GitProxy
485503

486504
<details>
487505
<summary>
488-
<strong> <a name="tempPassword_sendEmail"></a>15.1. [Optional] Property GitProxy configuration file > tempPassword > sendEmail</strong>
506+
<strong> <a name="tempPassword_sendEmail"></a>16.1. [Optional] Property GitProxy configuration file > tempPassword > sendEmail</strong>
489507

490508
</summary>
491509
<blockquote>
@@ -500,7 +518,7 @@ description: JSON schema reference documentation for GitProxy
500518

501519
<details>
502520
<summary>
503-
<strong> <a name="tempPassword_emailConfig"></a>15.2. [Optional] Property GitProxy configuration file > tempPassword > emailConfig</strong>
521+
<strong> <a name="tempPassword_emailConfig"></a>16.2. [Optional] Property GitProxy configuration file > tempPassword > emailConfig</strong>
504522

505523
</summary>
506524
<blockquote>
@@ -520,4 +538,4 @@ description: JSON schema reference documentation for GitProxy
520538
</details>
521539

522540
----------------------------------------------------------------------------------------------------------------------------
523-
Generated using [json-schema-for-humans](https://github.com/coveooss/json-schema-for-humans) on 2024-10-02 at 13:21:09 -0400
541+
Generated using [json-schema-for-humans](https://github.com/coveooss/json-schema-for-humans) on 2024-10-22 at 16:44:20 +0100

0 commit comments

Comments
 (0)