Skip to content

Commit

Permalink
[sample] Enhance black/white list feature of samples/proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
pajama-coder committed Jul 5, 2024
1 parent ad5a517 commit 666abb2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions samples/proxy/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@ if (config.proxy.http) {
return 'tunnel'
} else {
var url = new URL(head.path)
$host = `${url.hostname}:${url.port}`
log('HTTP', head.method, head.path)
return 'forward'
if (isTargetAllowed(url.hostname)) {
$host = `${url.hostname}:${url.port}`
log('HTTP', head.method, head.path)
return 'forward'
} else {
return 'forbidden'
}
}
}
}, {
Expand All @@ -109,7 +113,10 @@ if (config.proxy.http) {
),
'forward': ($=>$
.muxHTTP(() => $host).to($=>$.connect(() => $host))
)
),
'forbidden': ($=>$
.replaceMessage(new Message({ status: 403 }))
),
}
)
)
Expand Down

0 comments on commit 666abb2

Please sign in to comment.