MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. dfch
    3. Posts
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    D Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 1
    • Groups 0

    Posts

    Recent Best Controversial
    • RE: MagicMirror server get info through proxy

      @lwvmobile Sorry for the necroposting and late reply, I had similar issue (magicmirror behind http/socks proxy) and couldn’t find any solutions, so with the help of AI I found the issue why tsocks, http_proxy etc env vars don’t work.

      The problem is that MagicMirror overrides the global network layer inside this block using its own new Agent({ connect: { rejectUnauthorized: false } }) constructor whenever self-signed certificates or custom configurations are evaluated [index.js]. This instantly deletes your global proxy settings.

      To fix this, merge your proxy dispatcher into MagicMirror’s option generation scheme so it is safely preserved.

      Fix that worked for me:

      Modify your getRequestOptions() block in /path/to/your/MagicMirror/js/http_fetcher.js to look exactly like this:

      getRequestOptions () {
                      const headers = {
                              "User-Agent": getUserAgent(),
                              ...this.customHeaders
                      };
                      
                      // 1. Initialize the ProxyAgent using undici
                      const { ProxyAgent } = require("undici");
                      const proxyDispatcher = new ProxyAgent({ uri: "http://192.168.1.1:1080" });
                      
                      // 2. Set the default dispatcher to use your proxy
                      const options = { 
                              headers,
                              dispatcher: proxyDispatcher 
                      };
      
                      if (this.selfSignedCert) {
                              // 3. Merge the proxy configuration if self-signed cert handling is active
                              options.dispatcher = new ProxyAgent({
                                      uri: "http://192.168.1.1:1080",
                                      connect: {
                                              rejectUnauthorized: false
                                      }
                              });
                      }
      
                      if (this.auth) {
                              if (this.auth.method === "bearer") {
                                      headers.Authorization = `Bearer ${this.auth.pass}`;
                              } else {
                                      headers.Authorization = `Basic ${Buffer.from(`${this.auth.user}:${this.auth.pass}`).toString("base64")}`;
                              }
                      }
      
                      return options;
              }
      

      IMPORTANT: Modify proxy url to the one you use, instead of “http://192.168.1.1:1080”

      It intercepts the raw options configuration object right before MagicMirror wraps it.
      If this.selfSignedCert evaluates to true, it swaps out MagicMirror’s isolated base Agent with a ProxyAgent block that handles both the proxy routing and the SSL bypass rules simultaneously [index.js].

      posted in Troubleshooting
      D
      dfch
    • 1 / 1