@@ -30,8 +30,10 @@ import {
30
30
followerKill ,
31
31
followerPid ,
32
32
} from './follower' ;
33
- import { getDappUrl } from './dapps' ;
33
+ import { getDappHost } from './dapps' ;
34
34
import * as settings from './settings' ;
35
+ import http from 'http' ;
36
+ import { proxy } from './proxy' ;
35
37
36
38
logger . transports . file . level = 'info' ;
37
39
@@ -53,6 +55,10 @@ const dapps: { [key: string]: string | undefined } = {
53
55
'kwenta.eth' : undefined ,
54
56
'staking.synthetix.eth' : undefined ,
55
57
} ;
58
+ const localDapps : { [ key : string ] : string | undefined } = {
59
+ 'kwenta.eth' : 'kwenta' ,
60
+ 'staking.synthetix.eth' : 'staking' ,
61
+ } ;
56
62
57
63
if ( process . env . NODE_ENV === 'production' ) {
58
64
const sourceMapSupport = require ( 'source-map-support' ) ;
@@ -204,15 +210,11 @@ function generateMenuItems() {
204
210
separator : {
205
211
type : 'separator' ,
206
212
} ,
207
- dapps : Object . entries ( dapps ) . map ( ( [ name , url ] ) => {
213
+ dapps : Object . entries ( localDapps ) . map ( ( [ name , shortcut ] ) => {
208
214
return {
209
- enabled : Boolean ( url ) ,
215
+ enabled : Boolean ( dapps [ name ] ) ,
210
216
label : name ,
211
- click : ( ) => {
212
- if ( url ) {
213
- shell . openExternal ( url ) ;
214
- }
215
- } ,
217
+ click : ( ) => shell . openExternal ( `http://${ shortcut } .localhost:8888` ) ,
216
218
} ;
217
219
} ) ,
218
220
quit : {
@@ -310,15 +312,12 @@ followerDaemon();
310
312
const followerCheck = setInterval ( followerDaemon , 10_000 ) ;
311
313
app . on ( 'will-quit' , ( ) => clearInterval ( followerCheck ) ) ;
312
314
313
- ipcMain . handle ( 'dapp' , async ( _event , ens : string ) => {
314
- if ( ! ( ens in dapps ) ) {
315
- dapps [ ens ] = undefined ;
316
- }
317
- return dapps [ ens ] ;
318
- } ) ;
315
+ ipcMain . handle ( 'dapp' , async ( _event , ens : string ) =>
316
+ dapps [ ens ] ? `http://${ localDapps [ ens ] } .localhost:8888` : null
317
+ ) ;
319
318
async function updateAllDapps ( ) {
320
319
Object . keys ( dapps ) . forEach ( ( ens ) =>
321
- getDappUrl ( ens ) . then ( ( url ) => {
320
+ getDappHost ( ens ) . then ( ( url ) => {
322
321
if ( url ) {
323
322
dapps [ ens ] = url ;
324
323
updateContextMenu ( ) ;
@@ -329,3 +328,19 @@ async function updateAllDapps() {
329
328
const dappsUpdater = setInterval ( updateAllDapps , 600_000 ) ; // 10 minutes
330
329
app . on ( 'will-quit' , ( ) => clearInterval ( dappsUpdater ) ) ;
331
330
waitForIpfs ( ) . then ( updateAllDapps ) . catch ( logger . error ) ;
331
+
332
+ http
333
+ . createServer ( ( req , res ) => {
334
+ const shortcut = `${ req . headers . host } ` . replace ( '.localhost:8888' , '' ) ;
335
+ const host = Object . keys ( localDapps ) . find (
336
+ ( key ) => localDapps [ key ] === shortcut
337
+ ) ;
338
+ if ( host && host in dapps && dapps [ host ] ) {
339
+ req . headers . host = dapps [ host ] ;
340
+ proxy ( { host : '127.0.0.1' , port : 8080 } , req , res ) ;
341
+ return ;
342
+ }
343
+ res . writeHead ( 404 ) ;
344
+ res . end ( 'Not found' ) ;
345
+ } )
346
+ . listen ( 8888 , '0.0.0.0' ) ;
0 commit comments