11/** @jsx jsx */
22import { jsx } from '@emotion/core'
3+ import axios from 'axios'
34import React , {
45 FormEventHandler ,
56 useCallback ,
@@ -20,20 +21,15 @@ import Ad from '../../components/Ad'
2021import useSetState from '../../hooks/use-set-state'
2122import { Profile } from '../../types'
2223import { ExistingProfiles , LastUsedProfile } from '../../utils/constant'
23- import { bareFetcher } from '../../utils/fetcher'
2424
2525const Page : React . FC = ( ) => {
2626 const history = useHistory ( )
2727 const protocol = window . location . protocol
2828 const [ name , setName ] = useState < string | undefined > ( )
2929 const [ host , setHost ] = useState < string | undefined > ( )
30- const [ helperHost , setHelperHost ] = useState < string | undefined > ( )
3130 const [ port , setPort ] = useState < string | undefined > ( )
32- const [ helperPort , setHelperPort ] = useState < string | undefined > ( )
3331 const [ key , setKey ] = useState < string | undefined > ( )
34- const [ useHelper , setUseHelper ] = useState < boolean > (
35- ( ) => protocol === 'https:' ,
36- )
32+ const [ useTls , setUseTls ] = useState < boolean > ( ( ) => protocol === 'https:' )
3733 const [
3834 existingProfiles ,
3935 setExistingProfiles ,
@@ -84,8 +80,7 @@ const Page: React.FC = () => {
8480 setHost ( '' )
8581 setPort ( '' )
8682 setKey ( '' )
87- setHelperHost ( '' )
88- setHelperPort ( '' )
83+ setUseTls ( protocol === 'https:' )
8984 }
9085
9186 const onSubmit : FormEventHandler = ( e ) => {
@@ -97,25 +92,15 @@ const Page: React.FC = () => {
9792
9893 setIsLoading ( true )
9994
100- const options =
101- useHelper && helperHost && helperPort
102- ? {
103- helperHost,
104- helperPort : Number ( helperPort ) ,
105- }
106- : undefined
107-
108- bareFetcher (
109- {
110- url : `http://${ host } :${ port } /v1/outbound` ,
95+ axios
96+ . request ( {
97+ url : `${ useTls ? 'https' : 'http' } ://${ host } :${ port } /v1/outbound` ,
11198 method : 'GET' ,
11299 timeout : 3000 ,
113100 headers : {
114101 'x-key' : key ,
115102 } ,
116- } ,
117- options ,
118- )
103+ } )
119104 . then ( ( res ) => {
120105 setHasError ( false )
121106
@@ -129,8 +114,7 @@ const Page: React.FC = () => {
129114 : 'ios' ,
130115 platformVersion : res . headers [ 'x-surge-version' ] || '' ,
131116 platformBuild : res . headers [ 'x-surge-build' ] || '' ,
132- helperHost : helperHost ,
133- helperPort : Number ( helperPort ) ,
117+ tls : useTls ,
134118 } )
135119
136120 resetFields ( )
@@ -184,16 +168,8 @@ const Page: React.FC = () => {
184168 </ a >
185169 </ p >
186170 < p tw = "leading-normal mb-2" >
187- 您已可通过 yasd-helper 实现 HTTPS 访问 Surge API。
188- </ p >
189- < p tw = "leading-normal" >
190- < a
191- href = "https://github.com/geekdada/yasd-helper"
192- target = "_blank"
193- rel = "noreferrer"
194- tw = "border-b border-solid border-teal-500" >
195- 🔗 查看
196- </ a >
171+ Surge Mac v4.0.6 (1280) 开始已支持开启 HTTPS API,故不再支持使用
172+ yasd-helper。
197173 </ p >
198174 </ div >
199175
@@ -243,43 +219,16 @@ const Page: React.FC = () => {
243219 setKey ( ( target as HTMLInputElement ) . value )
244220 }
245221 />
246- < div >
247- < div >
248- < Checkbox
249- disabled = { protocol === 'https:' }
250- checked = { useHelper }
251- onChange = { ( ) => setUseHelper ( ( prev ) => ! prev ) } >
252- 使用 yasd-helper 中转
253- </ Checkbox >
254- </ div >
255222
256- { useHelper && (
257- < React . Fragment >
258- < Input
259- type = "text"
260- required = { protocol === 'https:' }
261- invalid = { ! ! hasError }
262- label = "Helper Host"
263- placeholder = "192.168.1.2.nip.io"
264- value = { helperHost }
265- onChange = { ( { target } ) =>
266- setHelperHost ( ( target as HTMLInputElement ) . value )
267- }
268- />
269- < Input
270- type = "number"
271- required = { protocol === 'https:' }
272- invalid = { ! ! hasError }
273- label = "Helper Port"
274- placeholder = "8443"
275- value = { helperPort }
276- onChange = { ( { target } ) =>
277- setHelperPort ( ( target as HTMLInputElement ) . value )
278- }
279- />
280- </ React . Fragment >
281- ) }
223+ < div >
224+ < Checkbox
225+ disabled = { protocol === 'https:' }
226+ checked = { useTls }
227+ onChange = { ( ) => setUseTls ( ( prev ) => ! prev ) } >
228+ HTTPS(请确保开启 < code > http-api-tls</ code > )
229+ </ Checkbox >
282230 </ div >
231+
283232 < div tw = "mt-6" >
284233 < LoadingButton
285234 type = "submit"
0 commit comments