Skip to content

Commit fd608f6

Browse files
committed
support custom cors-proxy
1 parent eb8833f commit fd608f6

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

apps/remix-ide/src/app/files/dgitProvider.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,21 @@ class DGitProvider extends Plugin {
8787
}
8888

8989
async addIsomorphicGitConfig(input) {
90-
9190
const token = await this.call('config' as any, 'getAppParameter', 'settings/gist-access-token')
91+
const gitlabToken = await this.call('config', 'getAppParameter', 'settings/gitlab-token')
92+
const corsproxy = await this.call('config', 'getAppParameter', 'settings/corsproxy-url')
9293

9394
let config = {
94-
corsProxy: 'https://corsproxy.remixproject.org/',
95+
corsProxy: corsproxy || 'https://corsproxy.remixproject.org/',
9596
http,
9697
onAuth: url => {
9798
url
98-
const auth = {
99+
const auth = url.startsWith('https://github.com') ? {
99100
username: input.token || token,
100101
password: ''
102+
} : {
103+
username: 'oauth2',
104+
password: input.token || gitlabToken
101105
}
102106
return auth
103107
}

apps/remix-ide/src/app/tabs/locales/en/filePanel.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
"filePanel.workspace.clone": "Clone Git Repository",
2828
"filePanel.workspace.cloneMessage": "Please provide a valid git repository url.",
2929
"filePanel.workspace.enterGitUrl": "Enter git repository url",
30+
"filePanel.workspace.enterCorsproxyUrl": "Enter cors proxy url, default to be https://corsproxy.remixproject.org/",
31+
"filePanel.workspace.gitRepoUrl": "Git Repo Url:",
32+
"filePanel.workspace.corsProxyUrl": "Cors Proxy Url (Optional):",
33+
"filePanel.workspace.corsproxyText1": "Note: To run CorsProxy on your system, run:",
34+
"filePanel.workspace.corsproxyText2": "Note: Cors Proxy Url must be end with /, such as http://127.0.0.1:9999/",
35+
"filePanel.workspace.corsproxyText3": "For more info, visit: <a>CorsProxy Documentation</a>",
3036
"filePanel.workspace.switch": "Switch To Workspace",
3137
"filePanel.workspace.solghaction": "Adds a preset yml file to run solidity unit tests on github actions CI.",
3238
"filePanel.solghaction": "Solidity Test Workflow",

libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export function Workspace() {
4646
const workspaceCreateTemplateInput = useRef()
4747
const intl = useIntl()
4848
const cloneUrlRef = useRef<HTMLInputElement>()
49+
const config = global.plugin.registry.get('config').api
50+
const corsproxyUrlRef = useRef<HTMLInputElement>()
4951
const initGitRepoRef = useRef<HTMLInputElement>()
5052
const filteredBranches = selectedWorkspace ? (selectedWorkspace.branches || []).filter((branch) => branch.name.includes(branchFilter) && branch.name !== 'HEAD').slice(0, 20) : []
5153
const currentBranch = selectedWorkspace ? selectedWorkspace.currentBranch : null
@@ -554,6 +556,11 @@ export function Workspace() {
554556

555557
const handleTypingUrl = () => {
556558
const url = cloneUrlRef.current.value
559+
const corsproxy = corsproxyUrlRef.current.value
560+
561+
if (corsproxy) {
562+
config.set('corsproxy', corsproxy)
563+
}
557564

558565
if (url) {
559566
global.dispatchCloneRepository(url)
@@ -1041,6 +1048,7 @@ export function Workspace() {
10411048
const cloneModalMessage = () => {
10421049
return (
10431050
<>
1051+
<div><FormattedMessage id="filePanel.workspace.gitRepoUrl" /></div>
10441052
<input
10451053
type="text"
10461054
data-id="modalDialogCustomPromptTextClone"
@@ -1050,6 +1058,43 @@ export function Workspace() {
10501058
ref={cloneUrlRef}
10511059
className="form-control"
10521060
/>
1061+
<div className="pt-4"><FormattedMessage id="filePanel.workspace.corsProxyUrl" /></div>
1062+
<input
1063+
type="text"
1064+
data-id="modalDialogCustomPromptTextCorsproxy"
1065+
placeholder={intl.formatMessage({
1066+
id: 'filePanel.workspace.enterCorsproxyUrl'
1067+
})}
1068+
ref={corsproxyUrlRef}
1069+
defaultValue={config.get('corsproxy')}
1070+
className="form-control"
1071+
/>
1072+
<div className="pt-2">
1073+
<FormattedMessage id="filePanel.workspace.corsproxyText1" />
1074+
<div className="p-1 pl-3">
1075+
<b>npm install -g @drafish/cors-proxy</b>
1076+
</div>
1077+
<div className="p-1 pl-3">
1078+
<b>cors-proxy start</b>
1079+
</div>
1080+
<div className="pt-2">
1081+
<FormattedMessage
1082+
id="filePanel.workspace.corsproxyText2"
1083+
/>
1084+
</div>
1085+
<div className="pt-2">
1086+
<FormattedMessage
1087+
id="filePanel.workspace.corsproxyText3"
1088+
values={{
1089+
a: (chunks) => (
1090+
<a href="https://github.com/drafish/cors-proxy" target="_blank">
1091+
{chunks}
1092+
</a>
1093+
)
1094+
}}
1095+
/>
1096+
</div>
1097+
</div>
10531098
</>
10541099
)
10551100
}

0 commit comments

Comments
 (0)