Skip to content

Commit 369ade6

Browse files
committed
support custom cors-proxy
1 parent b302fe1 commit 369ade6

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,19 @@ class DGitProvider extends Plugin {
7474
}
7575

7676
async parseInput(input) {
77+
const corsproxy = await this.call('config', 'getAppParameter', 'settings/corsproxy-url')
78+
const gitlabToken = await this.call('config', 'getAppParameter', 'settings/gitlab-token')
7779
return {
78-
corsProxy: 'https://corsproxy.remixproject.org/',
80+
corsProxy: corsproxy || 'https://corsproxy.remixproject.org/',
7981
http,
8082
onAuth: url => {
8183
url
82-
const auth = {
84+
const auth = url.startsWith('https://github.com') ? {
8385
username: input.token,
8486
password: ''
87+
} : {
88+
username: 'oauth2',
89+
password: gitlabToken
8590
}
8691
return auth
8792
}

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
@@ -49,6 +49,8 @@ export function Workspace() {
4949
const workspaceCreateTemplateInput = useRef()
5050
const intl = useIntl()
5151
const cloneUrlRef = useRef<HTMLInputElement>()
52+
const config = global.plugin.registry.get('config').api
53+
const corsproxyUrlRef = useRef<HTMLInputElement>()
5254
const initGitRepoRef = useRef<HTMLInputElement>()
5355
const filteredBranches = selectedWorkspace ? (selectedWorkspace.branches || []).filter((branch) => branch.name.includes(branchFilter) && branch.name !== 'HEAD').slice(0, 20) : []
5456
const currentBranch = selectedWorkspace ? selectedWorkspace.currentBranch : null
@@ -423,6 +425,11 @@ export function Workspace() {
423425

424426
const handleTypingUrl = () => {
425427
const url = cloneUrlRef.current.value
428+
const corsproxy = corsproxyUrlRef.current.value
429+
430+
if (corsproxy) {
431+
config.set('corsproxy', corsproxy)
432+
}
426433

427434
if (url) {
428435
global.dispatchCloneRepository(url)
@@ -905,6 +912,7 @@ export function Workspace() {
905912
const cloneModalMessage = () => {
906913
return (
907914
<>
915+
<div><FormattedMessage id="filePanel.workspace.gitRepoUrl" /></div>
908916
<input
909917
type="text"
910918
data-id="modalDialogCustomPromptTextClone"
@@ -914,6 +922,43 @@ export function Workspace() {
914922
ref={cloneUrlRef}
915923
className="form-control"
916924
/>
925+
<div className="pt-4"><FormattedMessage id="filePanel.workspace.corsProxyUrl" /></div>
926+
<input
927+
type="text"
928+
data-id="modalDialogCustomPromptTextCorsproxy"
929+
placeholder={intl.formatMessage({
930+
id: 'filePanel.workspace.enterCorsproxyUrl'
931+
})}
932+
ref={corsproxyUrlRef}
933+
defaultValue={config.get('corsproxy')}
934+
className="form-control"
935+
/>
936+
<div className="pt-2">
937+
<FormattedMessage id="filePanel.workspace.corsproxyText1" />
938+
<div className="p-1 pl-3">
939+
<b>npm install -g @drafish/cors-proxy</b>
940+
</div>
941+
<div className="p-1 pl-3">
942+
<b>cors-proxy start</b>
943+
</div>
944+
<div className="pt-2">
945+
<FormattedMessage
946+
id="filePanel.workspace.corsproxyText2"
947+
/>
948+
</div>
949+
<div className="pt-2">
950+
<FormattedMessage
951+
id="filePanel.workspace.corsproxyText3"
952+
values={{
953+
a: (chunks) => (
954+
<a href="https://github.com/drafish/cors-proxy" target="_blank">
955+
{chunks}
956+
</a>
957+
)
958+
}}
959+
/>
960+
</div>
961+
</div>
917962
</>
918963
)
919964
}

0 commit comments

Comments
 (0)