Skip to content

Commit 4ba0343

Browse files
committed
support custom cors-proxy
1 parent 26c7201 commit 4ba0343

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)
@@ -910,6 +917,7 @@ export function Workspace() {
910917
const cloneModalMessage = () => {
911918
return (
912919
<>
920+
<div><FormattedMessage id="filePanel.workspace.gitRepoUrl" /></div>
913921
<input
914922
type="text"
915923
data-id="modalDialogCustomPromptTextClone"
@@ -919,6 +927,43 @@ export function Workspace() {
919927
ref={cloneUrlRef}
920928
className="form-control"
921929
/>
930+
<div className="pt-4"><FormattedMessage id="filePanel.workspace.corsProxyUrl" /></div>
931+
<input
932+
type="text"
933+
data-id="modalDialogCustomPromptTextCorsproxy"
934+
placeholder={intl.formatMessage({
935+
id: 'filePanel.workspace.enterCorsproxyUrl'
936+
})}
937+
ref={corsproxyUrlRef}
938+
defaultValue={config.get('corsproxy')}
939+
className="form-control"
940+
/>
941+
<div className="pt-2">
942+
<FormattedMessage id="filePanel.workspace.corsproxyText1" />
943+
<div className="p-1 pl-3">
944+
<b>npm install -g @drafish/cors-proxy</b>
945+
</div>
946+
<div className="p-1 pl-3">
947+
<b>cors-proxy start</b>
948+
</div>
949+
<div className="pt-2">
950+
<FormattedMessage
951+
id="filePanel.workspace.corsproxyText2"
952+
/>
953+
</div>
954+
<div className="pt-2">
955+
<FormattedMessage
956+
id="filePanel.workspace.corsproxyText3"
957+
values={{
958+
a: (chunks) => (
959+
<a href="https://github.com/drafish/cors-proxy" target="_blank">
960+
{chunks}
961+
</a>
962+
)
963+
}}
964+
/>
965+
</div>
966+
</div>
922967
</>
923968
)
924969
}

0 commit comments

Comments
 (0)