@@ -53,6 +53,7 @@ if (numCPUs > 0 && cluster.isPrimary) {
5353 //uv config
5454 app . use ( '/uv/' , express . static ( uvPath ) ) ;
5555 //env vars for the unlock feature
56+ //analytics object
5657 let key = process . env . KEY || '' ;
5758 if ( ! key || key === undefined || key === null || key === '' ) {
5859 key = 'unlock' ;
@@ -65,9 +66,13 @@ if (numCPUs > 0 && cluster.isPrimary) {
6566 //only block /,/404,/apps,/error,/search,/settings and /index if the key or cookie is not present
6667 if ( bare . shouldRoute ( req ) ) {
6768 try {
68- for ( let i in blacklisted )
69- if ( req . headers [ 'x-bare-host' ] ?. includes ( blacklisted [ i ] ) )
70- return res . end ( 'Denied' ) ;
69+ if ( ! req . headers . cookie ?. includes ( 'allowads' ) ) {
70+ for ( let i in blacklisted )
71+ if (
72+ req . headers [ 'x-bare-host' ] ?. includes ( blacklisted [ i ] )
73+ )
74+ return res . end ( 'Denied' ) ;
75+ }
7176 bare . routeRequest ( req , res ) ;
7277 } catch ( error ) {
7378 console . error ( error ) ;
@@ -180,6 +185,25 @@ if (numCPUs > 0 && cluster.isPrimary) {
180185 return ;
181186 }
182187 } ) ;
188+ app . get ( '/disable-ads' , ( req , res ) => {
189+ if ( req . headers . cookie ?. includes ( 'allowads' ) ) {
190+ res . clearCookie ( 'allowads' ) ;
191+ res . writeHead ( 302 , {
192+ Location : '/settings' ,
193+ } ) ;
194+ res . end ( 'Disabled ads' ) ;
195+ return ;
196+ } else {
197+ res . writeHead ( 302 , {
198+ Location : '/settings' ,
199+ 'Set-Cookie' :
200+ 'allowads=allowads; Path=/; expires=Thu, 31 Dec 2099 23:59:59 GMT;' ,
201+ } ) ;
202+ res . end ( 'Ads enabled' ) ;
203+ return ;
204+ }
205+ } ) ;
206+ // Define the /analytics endpoint
183207 app . use ( ( req , res ) => {
184208 res . writeHead ( 302 , {
185209 Location : '/404' ,
0 commit comments