Skip to content

Commit 14c58c5

Browse files
authored
Merge pull request #50 from GunnarLieb/development
better information in dev env, if debugger is not accessible
2 parents b78b4da + aecbe68 commit 14c58c5

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

ModuleConfig.cfc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ component {
4747
// The debugger will still track requests even in non debug mode.
4848
debugMode : controller.getSetting( name = "environment", defaultValue = "production" ) == "development",
4949
// The URL password to use to activate it on demand
50+
// if set to cb:null, will generate random password
51+
// to enable debugger in dev environment set to empty or custom password
52+
// in live environment leave cb:null or set your own password
5053
debugPassword : "cb:null",
5154
// This flag enables/disables the end of request debugger panel docked to the bottem of the page.
5255
// If you disable i, then the only way to visualize the debugger is via the `/cbdebugger` endpoint

handlers/Main.cfc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,21 @@ component extends="coldbox.system.RestHandler" {
3030
* Debugger disabled event
3131
*/
3232
function disabled( event, rc, prc ){
33+
var data = "Page Not Found";
34+
35+
if ( getSetting("environment") == "DEVELOPMENT" ){
36+
data = ' isDebugCookieValid defined: ' & debuggerService.isDebugCookieValid() ;
37+
data &= ', secretKey defined: ' & debuggerService.isSecretKeyDefined() ;
38+
data &= ', doesCookieMatchesSecretKey: ' & debuggerService.doesCookieMatchesSecretKey() ;
39+
40+
data &= ', debugMode: ' & debuggerService.getDebugMode();
41+
}
42+
3343
event.renderData(
3444
statusCode = 404,
3545
statusText = "Not Found",
3646
type = "text",
37-
data = "Page Not Found"
47+
data = data
3848
);
3949
}
4050

models/DebuggerService.cfc

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,33 @@ component
146146
*/
147147
boolean function getDebugMode(){
148148
// If no secretKey has been set, don't allow debug mode
149-
if ( not ( len( variables.secretKey ) ) ) {
149+
if ( not ( isSecretKeyDefined() ) ) {
150150
return false;
151151
}
152152
// If Cookie exists, it's value is used.
153153
if ( isDebugCookieValid() ) {
154154
// Must be equal to the current secret key
155-
if ( cookie[ variables.cookieName ] == variables.secretKey ) {
156-
return true;
157-
} else {
158-
return false;
159-
}
155+
return doesCookieMatchesSecretKey()
160156
}
161157

162158
// If there is no cookie, then use default to app setting
163159
return variables.debugMode;
164160
}
161+
162+
/**
163+
* returns boolean if secret key is defined
164+
* init() will set secret key
165+
*/
166+
boolean function isSecretKeyDefined(){
167+
return javacast('Boolean',len( variables.secretKey ));
168+
}
169+
170+
/**
171+
* checks if cookie matches secret key
172+
*/
173+
boolean function doesCookieMatchesSecretKey(){
174+
return cookie[ variables.cookieName ] == variables.secretKey;
175+
}
165176

166177
/**
167178
* Checks if the debug cookie is a valid cookie. Boolean

0 commit comments

Comments
 (0)