Skip to content

Commit b95486e

Browse files
committed
support custom cors-proxy
1 parent 0db9e5f commit b95486e

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ class DGitProvider extends Plugin {
5959
}
6060

6161
async parseInput (input) {
62+
const corsproxy = await this.call('config', 'getAppParameter', 'corsproxy')
6263
return {
63-
corsProxy: 'https://corsproxy.remixproject.org/',
64+
corsProxy: corsproxy || 'https://corsproxy.remixproject.org/',
6465
http,
6566
onAuth: url => {
6667
url

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
"filePanel.workspace.clone": "Clone Git Repository",
2323
"filePanel.workspace.cloneMessage": "Please provide a valid git repository url.",
2424
"filePanel.workspace.enterGitUrl": "Enter git repository url",
25+
"filePanel.workspace.enterCorsproxyUrl": "Enter cors proxy url, default to be https://corsproxy.remixproject.org/",
26+
"filePanel.workspace.gitRepoUrl": "Git Repo Url:",
27+
"filePanel.workspace.corsProxyUrl": "Cors Proxy Url (Optional):",
28+
"filePanel.workspace.corsproxyText1": "Note: To run CorsProxy on your system, run:",
29+
"filePanel.workspace.corsproxyText2": "Note: Cors Proxy Url must be end with /, such as http://127.0.0.1:9999/",
30+
"filePanel.workspace.corsproxyText3": "For more info, visit: <a>CorsProxy Documentation</a>",
2531
"filePanel.workspace.switch": "Switch To Workspace",
2632
"filePanel.workspace.solghaction": "Adds a preset yml file to run solidity unit tests on github actions CI.",
2733
"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
@@ -44,6 +44,8 @@ export function Workspace() {
4444
const workspaceCreateTemplateInput = useRef()
4545
const intl = useIntl()
4646
const cloneUrlRef = useRef<HTMLInputElement>()
47+
const config = global.plugin.registry.get('config').api
48+
const corsproxyUrlRef = useRef<HTMLInputElement>()
4749
const initGitRepoRef = useRef<HTMLInputElement>()
4850
const filteredBranches = selectedWorkspace ? (selectedWorkspace.branches || []).filter((branch) => branch.name.includes(branchFilter) && branch.name !== 'HEAD').slice(0, 20) : []
4951
const currentBranch = selectedWorkspace ? selectedWorkspace.currentBranch : null
@@ -395,6 +397,11 @@ export function Workspace() {
395397

396398
const handleTypingUrl = () => {
397399
const url = cloneUrlRef.current.value
400+
const corsproxy = corsproxyUrlRef.current.value
401+
402+
if (corsproxy) {
403+
config.set('corsproxy', corsproxy)
404+
}
398405

399406
if (url) {
400407
global.dispatchCloneRepository(url)
@@ -870,6 +877,7 @@ export function Workspace() {
870877
const cloneModalMessage = () => {
871878
return (
872879
<>
880+
<div><FormattedMessage id="filePanel.workspace.gitRepoUrl" /></div>
873881
<input
874882
type="text"
875883
data-id="modalDialogCustomPromptTextClone"
@@ -879,6 +887,43 @@ export function Workspace() {
879887
ref={cloneUrlRef}
880888
className="form-control"
881889
/>
890+
<div className="pt-4"><FormattedMessage id="filePanel.workspace.corsProxyUrl" /></div>
891+
<input
892+
type="text"
893+
data-id="modalDialogCustomPromptTextCorsproxy"
894+
placeholder={intl.formatMessage({
895+
id: 'filePanel.workspace.enterCorsproxyUrl'
896+
})}
897+
ref={corsproxyUrlRef}
898+
defaultValue={config.get('corsproxy')}
899+
className="form-control"
900+
/>
901+
<div className="pt-2">
902+
<FormattedMessage id="filePanel.workspace.corsproxyText1" />
903+
<div className="p-1 pl-3">
904+
<b>npm install -g @drafish/cors-proxy</b>
905+
</div>
906+
<div className="p-1 pl-3">
907+
<b>cors-proxy start</b>
908+
</div>
909+
<div className="pt-2">
910+
<FormattedMessage
911+
id="filePanel.workspace.corsproxyText2"
912+
/>
913+
</div>
914+
<div className="pt-2">
915+
<FormattedMessage
916+
id="filePanel.workspace.corsproxyText3"
917+
values={{
918+
a: (chunks) => (
919+
<a href="https://github.com/drafish/cors-proxy" target="_blank">
920+
{chunks}
921+
</a>
922+
)
923+
}}
924+
/>
925+
</div>
926+
</div>
882927
</>
883928
)
884929
}

0 commit comments

Comments
 (0)