Skip to content

Commit

Permalink
feat: allow for providing an alternative domain for the proxy
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
06kellyjac committed Oct 17, 2024
1 parent 0d63842 commit 083572c
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 28 deletions.
1 change: 0 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
VITE_API_URI=http://localhost:8080
VITE_SERVER_URI=http://localhost:8000
4 changes: 4 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"description": "Customisable questions to add to attestation form",
"type": "object"
},
"domains": {
"description": "Provide domains to use alternative to the defaults",
"type": "object"
},
"privateOrganizations": {
"description": "Pattern searches for listed private organizations are disabled",
"type": "array"
Expand Down
1 change: 1 addition & 0 deletions proxy.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
}
]
},
"domains": {},
"privateOrganizations": [],
"urlShortener": "",
"contactEmail": "",
Expand Down
9 changes: 9 additions & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let _privateOrganizations = defaultSettings.privateOrganizations;
let _urlShortener = defaultSettings.urlShortener;
let _contactEmail = defaultSettings.contactEmail;
let _csrfProtection = defaultSettings.csrfProtection;
let _domains = defaultSettings.domains;

// Get configured proxy URL
const getProxyUrl = () => {
Expand Down Expand Up @@ -180,6 +181,13 @@ const getSSLCertPath = () => {
return _sslCertPath;
};

const getDomains = () => {
if (_userSettings && _userSettings.domains) {
_domains = _userSettings.domains;

Check warning on line 186 in src/config/index.js

View check run for this annotation

Codecov / codecov/patch

src/config/index.js#L185-L186

Added lines #L185 - L186 were not covered by tests
}
return _domains;

Check warning on line 188 in src/config/index.js

View check run for this annotation

Codecov / codecov/patch

src/config/index.js#L188

Added line #L188 was not covered by tests
};

exports.getAPIs = getAPIs;
exports.getProxyUrl = getProxyUrl;
exports.getAuthorisedList = getAuthorisedList;
Expand All @@ -197,3 +205,4 @@ exports.getContactEmail = getContactEmail;
exports.getCSRFProtection = getCSRFProtection;
exports.getSSLKeyPath = getSSLKeyPath;
exports.getSSLCertPath = getSSLCertPath;
exports.getDomains = getDomains;
13 changes: 13 additions & 0 deletions src/service/proxyURL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { GIT_PROXY_SERVER_PORT: PROXY_HTTP_PORT, GIT_PROXY_UI_PORT: UI_PORT } =
require('../config/env').Vars;
const config = require('../config');

module.exports = {
getProxyURL: (req) => {
const defaultURL = `${req.protocol}://${req.headers.host}`.replace(

Check warning on line 7 in src/service/proxyURL.js

View check run for this annotation

Codecov / codecov/patch

src/service/proxyURL.js#L7

Added line #L7 was not covered by tests
`:${UI_PORT}`,
`:${PROXY_HTTP_PORT}`,
);
return config.getDomains().proxy ?? defaultURL;

Check warning on line 11 in src/service/proxyURL.js

View check run for this annotation

Codecov / codecov/patch

src/service/proxyURL.js#L11

Added line #L11 was not covered by tests
},
};
5 changes: 4 additions & 1 deletion src/service/routes/push.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const express = require('express');
const router = new express.Router();
const db = require('../../db');
const { getProxyURL } = require('../proxyURL');

router.get('/', async (req, res) => {
const proxyURL = getProxyURL(req);

Check warning on line 7 in src/service/routes/push.js

View check run for this annotation

Codecov / codecov/patch

src/service/routes/push.js#L7

Added line #L7 was not covered by tests
const query = {
type: 'push',
};
Expand All @@ -18,7 +20,8 @@ router.get('/', async (req, res) => {
query[k] = v;
}

res.send(await db.getPushes(query));
const qd = await db.getPushes(query);
res.send(qd.map((d) => ({ ...d, proxyURL })));

Check warning on line 24 in src/service/routes/push.js

View check run for this annotation

Codecov / codecov/patch

src/service/routes/push.js#L23-L24

Added lines #L23 - L24 were not covered by tests
});

router.get('/:id', async (req, res) => {
Expand Down
5 changes: 4 additions & 1 deletion src/service/routes/repo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const express = require('express');
const router = new express.Router();
const db = require('../../db');
const { getProxyURL } = require('../proxyURL');

router.get('/', async (req, res) => {
const proxyURL = getProxyURL(req);

Check warning on line 7 in src/service/routes/repo.js

View check run for this annotation

Codecov / codecov/patch

src/service/routes/repo.js#L7

Added line #L7 was not covered by tests
const query = {
type: 'push',
};
Expand All @@ -18,7 +20,8 @@ router.get('/', async (req, res) => {
query[k] = v;
}

res.send(await db.getRepos(query));
const qd = await db.getRepos(query);
res.send(qd.map((d) => ({ ...d, proxyURL })));

Check warning on line 24 in src/service/routes/repo.js

View check run for this annotation

Codecov / codecov/patch

src/service/routes/repo.js#L23-L24

Added lines #L23 - L24 were not covered by tests
});

router.get('/:name', async (req, res) => {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/views/RepoDetails/RepoDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export default function RepoDetails() {
if (isLoading) return <div>Loading...</div>;
if (isError) return <div>Something went wrong ...</div>;

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

return (
<GridContainer>
Expand Down
4 changes: 2 additions & 2 deletions src/ui/views/RepoList/Components/RepoOverview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ export default function Repositories(props) {
});
};

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

return (
<TableRow>
Expand Down
Loading

0 comments on commit 083572c

Please sign in to comment.