@@ -162,7 +162,8 @@ function getTunnelId(path: string): string {
162162export default {
163163 async fetch ( request , env , ctx ) : Promise < Response > {
164164 try {
165- const isSecretSet = isValidSecret ( env . WEBHOOKS_PROXY_TUNNEL_SECRET ) ;
165+ const secret = env . WEBHOOKS_PROXY_TUNNEL_SECRET ;
166+ const secretIsValid = isValidSecret ( secret ) ;
166167 const url = new URL ( request . url ) ;
167168 if ( url . pathname . startsWith ( "/tunnel/" ) ) {
168169 const tunnelId = getTunnelId ( url . pathname ) ;
@@ -171,15 +172,14 @@ export default {
171172 const stats = await stub . stats ( ) ;
172173
173174 return new Response (
174- tunnelPage ( url . origin , tunnelId , stats , isSecretSet ) ,
175+ tunnelPage ( url . origin , tunnelId , stats , secretIsValid ) ,
175176 {
176177 headers : { "content-type" : "text/html" } ,
177178 } ,
178179 ) ;
179180 } else if ( url . pathname . startsWith ( "/connect/" ) ) {
180181 const tunnelId = getTunnelId ( url . pathname ) ;
181- if ( isSecretSet ) {
182- const secret = env . WEBHOOKS_PROXY_TUNNEL_SECRET ;
182+ if ( secretIsValid ) {
183183 const swspHeader = request . headers . get ( "Sec-WebSocket-Protocol" ) ;
184184 if ( ! swspHeader ) {
185185 return new Response (
@@ -240,7 +240,7 @@ export default {
240240 } else if ( url . pathname == "/" ) {
241241 return new Response (
242242 homePage ( {
243- isSecretSet,
243+ isSecretSet : secretIsValid ,
244244 } ) ,
245245 {
246246 headers : { "content-type" : "text/html" } ,
@@ -271,7 +271,7 @@ function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
271271 } ) ;
272272}
273273
274- function isValidSecret ( secret : unknown ) : boolean {
274+ function isValidSecret ( secret : unknown ) : secret is string {
275275 // A valid secret is a string of 40 characters (30 bytes in Base64).
276276 return typeof secret === "string" && secret . length === 40 ;
277277}
0 commit comments