@@ -8,6 +8,9 @@ const TIMEOUT = process.env.API_TIMEOUT_LIMIT ? parseInt(process.env.API_TIMEOUT
88// If present, set CORS allowed origins for responses
99const ALLOWED_ORIGINS = process . env . API_CORS_ORIGIN || '*' ;
1010
11+ // Disable everything :( Setting this env var will turn off the instance, and show message
12+ const DISABLE_EVERYTHING = ! ! process . env . VITE_DISABLE_EVERYTHING ;
13+
1114// Set the platform currently being used
1215let PLATFORM = 'NETLIFY' ;
1316if ( process . env . PLATFORM ) { PLATFORM = process . env . PLATFORM . toUpperCase ( ) ; }
@@ -21,7 +24,6 @@ const headers = {
2124 'Content-Type' : 'application/json;charset=UTF-8' ,
2225} ;
2326
24-
2527const timeoutErrorMsg = 'You can re-trigger this request, by clicking "Retry"\n'
2628+ 'If you\'re running your own instance of Web Check, then you can '
2729+ 'resolve this issue, by increasing the timeout limit in the '
@@ -31,6 +33,14 @@ const timeoutErrorMsg = 'You can re-trigger this request, by clicking "Retry"\n'
3133+ 'in order to keep running costs affordable, so that Web Check can '
3234+ 'remain freely available for everyone.' ;
3335
36+ const disabledErrorMsg = 'Error - WebCheck Temporarily Disabled.\n\n'
37+ + 'We\'re sorry, but due to the increased cost of running Web Check '
38+ + 'we\'ve had to temporatily disable the public instand. '
39+ + 'We\'re activley looking for affordable ways to keep Web Check running, '
40+ + 'while free to use for everybody.\n'
41+ + 'In the meantime, since we\'ve made our code free and open source, '
42+ + 'you can get Web Check running on your own system, by following the instructions in our GitHub repo' ;
43+
3444// A middleware function used by all API routes on all platforms
3545const commonMiddleware = ( handler ) => {
3646
@@ -45,6 +55,11 @@ const commonMiddleware = (handler) => {
4555
4656 // Vercel
4757 const vercelHandler = async ( request , response ) => {
58+
59+ if ( DISABLE_EVERYTHING ) {
60+ response . status ( 503 ) . json ( { error : disabledErrorMsg } ) ;
61+ }
62+
4863 const queryParams = request . query || { } ;
4964 const rawUrl = queryParams . url ;
5065
@@ -83,6 +98,15 @@ const commonMiddleware = (handler) => {
8398 const queryParams = event . queryStringParameters || event . query || { } ;
8499 const rawUrl = queryParams . url ;
85100
101+ if ( DISABLE_EVERYTHING ) {
102+ callback ( null , {
103+ statusCode : 503 ,
104+ body : JSON . stringify ( { error : 'Web-Check is temporarily disabled. Please try again later.' } ) ,
105+ headers,
106+ } ) ;
107+ return ;
108+ }
109+
86110 if ( ! rawUrl ) {
87111 callback ( null , {
88112 statusCode : 500 ,
0 commit comments