[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"blog-post-commandbox-rewrite-woes-and-how-to-debug-them":3},{"id":4,"title":5,"body":6,"date":307,"description":12,"extension":308,"meta":309,"navigation":310,"path":311,"published":310,"seo":312,"slug":313,"stem":314,"summary":5,"tags":315,"__hash__":319},"blog/blog/2017-09-15-commandbox-rewrite-woes-and-how-to-debug-them.md","CommandBox, Rewrite Woes & How to Debug Them",{"type":7,"value":8,"toc":305},"minimark",[9,13,18,21,25,45,51,55,58,75,78,82,88,95,245,248,295,298,301],[10,11,12],"p",{},"Over the last day and a half, I've been plagued by what seemed an oddity when working on a logging demo in CommandBox. It had me thrown to the point of thinking I came across some strange bug. So I wanted to touch on how to debug the network requests and responses going on behind the scenes of a CommandBox server instance.",[14,15,17],"h4",{"id":16},"what-was-happening","What was happening?",[10,19,20],{},"Well, when I fired up my application in CommandBox and went to check for a log entry, I was literally seeing double. Two identical log entries and no idea how, or why, it was happening. At this stage, I was running an app using FW/1 but after checking with Sean Corfield on the CFML Slack, we were able to confirm there were two requests happening but not due to FW/1. Off to the box-products channel I went, to query Brad Wood. Brad, as always, was quite helpful (cheers Brad) and had an answer for me right away along with a handy tip on how he came to the result.",[14,22,24],{"id":23},"so-what-really-happened","So what really happened?",[10,26,27,28,32,33,36,37,40,41,44],{},"Apparently, the browser I was using (Chrome) was sending a request for a ",[29,30,31],"code",{},"favicon.ico"," file that, in this case, clearly did not exist. The bad request, it seems, is still caught and matched to a rewrite which, in turn, tries to make a request to ",[29,34,35],{},"/index.cfm/favicon.ico",". This obviously doesn't exist either but the request still makes it far enough to trigger the logs I had in place. This resulted in an extra request than I expected. This ultimately was due to me having ",[29,38,39],{},"\"rewrites\":{\"enable\":true}"," in my ",[29,42,43],{},"server.json",". I assume the rewrite that catches this is something set up in Undertow/Tuckey Rewrite Filter for the default rewriting available from CommandBox. I'm definitely not sure of this, however.",[46,47,48],"blockquote",{},[10,49,50],{},"Apparently it's a known issue that Chrome makes this request every time. I'm not sure about other browsers.",[14,52,54],{"id":53},"how-did-we-come-to-this","How did we come to this?",[10,56,57],{},"When firing up a server instance in CommandBox, you can make debugging info available right in the console.",[59,60,65],"pre",{"className":61,"code":62,"language":63,"meta":64,"style":64},"language-shell shiki shiki-themes github-light github-dark github-dark monokai","#> server start --debug --console\n","shell","",[29,66,67],{"__ignoreMap":64},[68,69,72],"span",{"class":70,"line":71},"line",1,[68,73,62],{"class":74},"sq-8i",[10,76,77],{},"This made it possible to see the requests being made and how the container/rewrite filter was processing/directing those requests.",[14,79,81],{"id":80},"how-can-you-get-around-this","How can you get around this?",[10,83,84,85,87],{},"The short answer is to filter out the request with a rewrite but, one way to deal with this is to include a rewrite that matches ",[29,86,31],{}," and return a 403/404/something.",[10,89,90,91,94],{},"In CommandBox, this can be done by adding a rule to a ",[29,92,93],{},"urlrewrite.xml"," for the Tuckey Rewrite Filter to pick up.",[59,96,100],{"className":97,"code":98,"language":99,"meta":64,"style":64},"language-xml shiki shiki-themes github-light github-dark github-dark monokai","\u003C?xml version=\"1.0\" encoding=\"utf-8\"?>\n\u003Curlrewrite>\n    \u003Crule>\n        \u003Cname>Intercept favicon.ico request\u003C/name>\n        \u003Cfrom>^/favicon.ico$\u003C/from>\n        \u003Cset type=\"status\">403\u003C/set>\n        \u003Cto>null\u003C/to>\n    \u003C/rule>\n\u003C/urlrewrite>\n","xml",[29,101,102,133,145,156,172,187,210,225,235],{"__ignoreMap":64},[68,103,104,108,111,115,118,122,125,127,130],{"class":70,"line":71},[68,105,107],{"class":106},"s__4a","\u003C?",[68,109,99],{"class":110},"sIn_X",[68,112,114],{"class":113},"s9ihy"," version",[68,116,117],{"class":106},"=",[68,119,121],{"class":120},"svw4x","\"1.0\"",[68,123,124],{"class":113}," encoding",[68,126,117],{"class":106},[68,128,129],{"class":120},"\"utf-8\"",[68,131,132],{"class":106},"?>\n",[68,134,136,139,142],{"class":70,"line":135},2,[68,137,138],{"class":106},"\u003C",[68,140,141],{"class":110},"urlrewrite",[68,143,144],{"class":106},">\n",[68,146,148,151,154],{"class":70,"line":147},3,[68,149,150],{"class":106},"    \u003C",[68,152,153],{"class":110},"rule",[68,155,144],{"class":106},[68,157,159,162,165,168,170],{"class":70,"line":158},4,[68,160,161],{"class":106},"        \u003C",[68,163,164],{"class":110},"name",[68,166,167],{"class":106},">Intercept favicon.ico request\u003C/",[68,169,164],{"class":110},[68,171,144],{"class":106},[68,173,175,177,180,183,185],{"class":70,"line":174},5,[68,176,161],{"class":106},[68,178,179],{"class":110},"from",[68,181,182],{"class":106},">^/favicon.ico$\u003C/",[68,184,179],{"class":110},[68,186,144],{"class":106},[68,188,190,192,195,198,200,203,206,208],{"class":70,"line":189},6,[68,191,161],{"class":106},[68,193,194],{"class":110},"set",[68,196,197],{"class":113}," type",[68,199,117],{"class":106},[68,201,202],{"class":120},"\"status\"",[68,204,205],{"class":106},">403\u003C/",[68,207,194],{"class":110},[68,209,144],{"class":106},[68,211,213,215,218,221,223],{"class":70,"line":212},7,[68,214,161],{"class":106},[68,216,217],{"class":110},"to",[68,219,220],{"class":106},">null\u003C/",[68,222,217],{"class":110},[68,224,144],{"class":106},[68,226,228,231,233],{"class":70,"line":227},8,[68,229,230],{"class":106},"    \u003C/",[68,232,153],{"class":110},[68,234,144],{"class":106},[68,236,238,241,243],{"class":70,"line":237},9,[68,239,240],{"class":106},"\u003C/",[68,242,141],{"class":110},[68,244,144],{"class":106},[10,246,247],{},"And including it in your server.json.",[59,249,253],{"className":250,"code":251,"language":252,"meta":64,"style":64},"language-json shiki shiki-themes github-light github-dark github-dark monokai","\"rewrites\":{\n    \"enable\":true,\n    \"config\":\"urlrewrite.xml\"\n}\n","json",[29,254,255,263,279,290],{"__ignoreMap":64},[68,256,257,260],{"class":70,"line":71},[68,258,259],{"class":120},"\"rewrites\"",[68,261,262],{"class":106},":{\n",[68,264,265,269,272,276],{"class":70,"line":135},[68,266,268],{"class":267},"sHysA","    \"enable\"",[68,270,271],{"class":106},":",[68,273,275],{"class":274},"s-7EV","true",[68,277,278],{"class":106},",\n",[68,280,281,284,286],{"class":70,"line":147},[68,282,283],{"class":267},"    \"config\"",[68,285,271],{"class":106},[68,287,289],{"class":288},"sSnWl","\"urlrewrite.xml\"\n",[68,291,292],{"class":70,"line":158},[68,293,294],{"class":106},"}\n",[10,296,297],{},"That's all for now. I thought the debugging features were pretty slick and super helpful in figuring out something that, while minor, was driving me crazy.",[10,299,300],{},"Cheers.",[302,303,304],"style",{},"html pre.shiki code .sq-8i, html code.shiki .sq-8i{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D;--shiki-sepia:#88846F}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html .sepia .shiki span {color: var(--shiki-sepia);background: var(--shiki-sepia-bg);font-style: var(--shiki-sepia-font-style);font-weight: var(--shiki-sepia-font-weight);text-decoration: var(--shiki-sepia-text-decoration);}html.sepia .shiki span {color: var(--shiki-sepia);background: var(--shiki-sepia-bg);font-style: var(--shiki-sepia-font-style);font-weight: var(--shiki-sepia-font-weight);text-decoration: var(--shiki-sepia-text-decoration);}html pre.shiki code .s__4a, html code.shiki .s__4a{--shiki-light:#24292E;--shiki-default:#E1E4E8;--shiki-dark:#E1E4E8;--shiki-sepia:#F8F8F2}html pre.shiki code .sIn_X, html code.shiki .sIn_X{--shiki-light:#22863A;--shiki-default:#85E89D;--shiki-dark:#85E89D;--shiki-sepia:#F92672}html pre.shiki code .s9ihy, html code.shiki .s9ihy{--shiki-light:#6F42C1;--shiki-default:#B392F0;--shiki-dark:#B392F0;--shiki-sepia:#A6E22E}html pre.shiki code .svw4x, html code.shiki .svw4x{--shiki-light:#032F62;--shiki-default:#9ECBFF;--shiki-dark:#9ECBFF;--shiki-sepia:#E6DB74}html pre.shiki code .sHysA, html code.shiki .sHysA{--shiki-light:#005CC5;--shiki-light-font-style:inherit;--shiki-default:#79B8FF;--shiki-default-font-style:inherit;--shiki-dark:#79B8FF;--shiki-dark-font-style:inherit;--shiki-sepia:#66D9EF;--shiki-sepia-font-style:italic}html pre.shiki code .s-7EV, html code.shiki .s-7EV{--shiki-light:#005CC5;--shiki-default:#79B8FF;--shiki-dark:#79B8FF;--shiki-sepia:#AE81FF}html pre.shiki code .sSnWl, html code.shiki .sSnWl{--shiki-light:#032F62;--shiki-default:#9ECBFF;--shiki-dark:#9ECBFF;--shiki-sepia:#CFCFC2}",{"title":64,"searchDepth":135,"depth":135,"links":306},[],"2017-09-15","md",{},true,"/blog/2017-09-15-commandbox-rewrite-woes-and-how-to-debug-them",{"title":5,"description":12},"commandbox-rewrite-woes-and-how-to-debug-them","blog/2017-09-15-commandbox-rewrite-woes-and-how-to-debug-them",[316,317,318],"CommandBox","URL Rewrites","Debugging","rF5uQxGXxSnuwHdj3kxhlVATBvUkDAiBru56bWZS_lw"]