DouweM / homebridge-unifi-occupancy

Homebridge plugin that adds HomeKit occupancy sensors for selected devices (and people) on your UniFi network to the iOS Home app: quickly see who's where and automate accordingly.
Apache License 2.0
41 stars 1 forks source link

404 error due to extra forward slash in get path #27

Open jarvismeier opened 5 months ago

jarvismeier commented 5 months ago

Describe The Bug: Since updating to Unifi 8.1.x the plugin errors out when attempting to connect/query the api path. Looking in the logs there is an extra forward slash which is generating the 404 error ie: https://10.0.1.xxx:8443//v2/api/fingerprint_devices/0

To Reproduce: Update self hosted Unifi to 8.1

Expected behavior: plugin should not retrieve 404 errors when contacting the API

Logs:


error: '<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1></body></html>',
  options: {
    rejectUnauthorized: false,
    jar: RequestJar { _jar: [CookieJar] },
    headers: { 'User-Agent': 'node.js unifi-events UniFi Events' },
    json: true,
    uri: 'https://10.0.1.xxx:8443//v2/api/site/default/clients/active',
    method: 'GET',
    callback: [Function: RP$callback],
    transform: undefined,
    simple: true,
    resolveWithFullResponse: false,
    transform2xxOnly: false
  },

Plugin Config:

N/a

Screenshots:

Environment:

DanielSchaffer commented 4 months ago

I'm seeing the same after updating my controller to 8.1

DanielSchaffer commented 4 months ago

I have my unifi controller behind an nginx proxy, so I was able to work around this by adding this to the server section:

        merge_slashes off;
        rewrite (.*?)//+(.*) $1/$2 permanent;

My understanding is that merge_slashes only allows nginx to treat multiple slashes as one, but it doesn't actually rewrite anything, so they'd still get passed through the proxy as-is. The rewrite doesn't work with it still on, I'm guessing because the regexp doesn't pick up the multiple slashes because of that merge_slashes behavior.