Skip to content

Commit af067e8

Browse files
lbogdanCompuIves
authored andcommitted
Add "ROOT_URL" build environment variable (codesandbox#610)
1 parent 606ff76 commit af067e8

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

packages/app/config/env.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const getHost = () => {
1818
return `http://${process.env.STAGING_BRANCH}.cs.lbogdan.tk`;
1919
}
2020

21+
if ('ROOT_URL' in process.env) {
22+
return process.env.ROOT_URL;
23+
}
24+
2125
return 'https://codesandbox.io';
2226
};
2327

packages/app/src/app/pages/Sandbox/SearchDependencies/DependencyHit/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ export default class DependencyHit extends React.PureComponent {
3434
}
3535

3636
makeSearchUrl(hitName: string) {
37-
return `https://codesandbox.io/search?refinementList%5Bnpm_dependencies.dependency%5D%5B0%5D=${hitName}&page=1`;
37+
return `${
38+
process.env.CODESANDBOX_HOST
39+
}/search?refinementList%5Bnpm_dependencies.dependency%5D%5B0%5D=${
40+
hitName
41+
}&page=1`;
3842
}
3943

4044
stopPropagation(e) {

packages/app/src/app/pages/common/Modals/ShareModal/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import {
2323
ButtonName,
2424
} from './elements';
2525

26-
const BUTTON_URL = 'https://codesandbox.io/static/img/play-codesandbox.svg';
26+
const BUTTON_URL = `${
27+
process.env.CODESANDBOX_HOST
28+
}/static/img/play-codesandbox.svg`;
2729

2830
class ShareView extends React.Component {
2931
state = {

packages/app/src/sandbox/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ function getId() {
2525
return document.location.host.match(re)[1];
2626
}
2727

28-
return document.location.host.match(/(.*)\.codesandbox/)[1];
28+
const hostRegex = host.replace(/https?:\/\//, '').replace(/\./g, '\\.');
29+
const sandboxRegex = new RegExp(`(.*)\\.${hostRegex}`);
30+
return document.location.host.match(sandboxRegex)[1];
2931
}
3032

3133
requirePolyfills().then(() => {

0 commit comments

Comments
 (0)