Debug Frontend Projects with Whistle: From Webpack DevServer to Legacy Setups
This guide shows how to integrate the Whistle proxy with frontend projects—whether using webpack devServer, a traditional setup without build tools, or custom plugins—by configuring domain‑based rules, handling CGI mocks, and leveraging exclude filters to enable seamless local debugging via real online URLs.
Using Whistle with Webpack DevServer
Most frontend projects use webpack. This example uses a create‑react‑app project named
my-app. After running
npm run start, the app is served at
localhost:3000. Localhost has limitations such as cookie domain restrictions and extra logic.
To overcome these, Whistle can map an online domain (e.g.,
qq.ketang.com) to the local server. Open Whistle’s rule editor at
127.0.0.1:8899, enable the Default rule, and add the rule:
<code>qq.ketang.com/ http://127.0.0.1:3000/</code>Save the rule, then configure the SwitchyOmega proxy to use Whistle. Accessing
https://qq.ketang.comin the browser loads the local
my-appwhile using the real domain.
What Whistle Does
The rule forwards all requests under
qq.ketang.com/to
http://127.0.0.1:3000/. Whistle supports various pattern‑matching modes for different scenarios.
Exclude Sub‑path CGI Forwarding
Use
excludeFilterto prevent certain CGI paths from being proxied:
<code># good – exclude CGI paths
qq.ketang.com/ http://127.0.0.1:3000/ excludeFilter://qq.ketang.com/cgi-proxy/</code>Wildcard or regex patterns can also be used:
<code># wildcard
qq.ketang.com/ http://127.0.0.1:3000/ excludeFilter://^qq.ketang.com/cgi-*</code> <code># regex
qq.ketang.com/ http://127.0.0.1:3000/ excludeFilter:///^\w+://qq\.ketang\.com/cgi-/</code>Mock Specific CGI Interfaces
Three ways to mock a CGI response:
Serve a local file:
qq.ketang.com/cgi-proxy/getMyName file:///User/dug/data/getMyName.jsonUse the Values panel:
qq.ketang.com/cgi-proxy/getMyName file://{ans.json}Use
xfilemode, which falls back to the online resource if the file is missing.
Legacy Projects Without Build Tools
For projects that serve static assets directly, map the online asset paths to local directories:
<code># CSS
qq.ketang.com/assets/css/ xfile:///User/dug/myWork/ketang_pro/assets/css/
# JS
qq.ketang.com/assets/js/ xfile:///User/dug/myWork/ketang_pro/assets/js/</code>Now requests to
/assets/css/and
/assets/js/are answered by the local files, enabling local modification and debugging.
Extending Whistle with Plugins
Special scenarios can be handled with plugins. For example, the
whistle.comboplugin splits combo URLs like
http://i.cdn.com/??x.js,y.js,z.jsinto separate requests.
<code># whistle.combo
https://github.com/whistle-plugins/whistle.combo</code>A collection of Whistle plugins is available at:
<code># Whistle plugins list
https://github.com/whistle-plugins</code>Tencent IMWeb Frontend Team
IMWeb Frontend Community gathering frontend development enthusiasts. Follow us for refined live courses by top experts, cutting‑edge technical posts, and to sharpen your frontend skills.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.