Did I find a legitimate bug or do I just not know what I’m doing?
I’m going with column B.
Behind the scenes for the last couple of days, I’ve been fighting with the image host installation/setup. I made some changes that broke things, I made more changes that may have broken things, and I did have to make some actual code modifications to the server to fix it.
You see, no one but me has upload access; so there was never a reason to have the linx-server upload page being served as root index. I started by adding a gallery link to the internal templates; but the more I thought about it the more I realized that didn’t need to be there. What I really needed to do was put the gallery on the root and move the upload stuff elsewhere.
So the first thing I did was change the configuration and readjust my nginx conf. I made my second fatal mistake here by looking at the behavior and writing a rewrite directive to add the trailing / to those URLs; this was because /upload != /upload/, so it would 404 if you didn’t add it.
Before I get in to what the rewrite directive broke, let’s talk about what actually broke on the server; the auth module. I could still upload from the phone just fine, but browser uploads broke. I started chasing my tail before turning on stdout logging and watching. The hangup now was the authorization. After moving the server to a path, the browser authorization broke.
So after a few hours of reading the code and googling all the syntax; I was lead to the apikeys.go file and tried a couple modifications; mostly hard-coding my site-path in to the configuration. This fixed the auth issue entirely. It no longer served 404s on requests for /upload/auth/. But now browser uploads were broken….and I don’t even remember how. On one hand, I remember thinking files were uploading and I wasn’t getting a URL returned. When I actually had a chance to sit down and look at the problem; nothing was uploading through the browser.
I put the entire thing aside saying I’d mess with it during the weekend; and I had a little bit of time last night that I poked around. I was reading the documentation on dropzone.js, which is what linx-server uses for it’s browser pages. So while reading all of this documentation something clicks and I jump in to it’s index.html template and add a trailing slash to the “upload” path in the code.
Now it works! Great! I’m excited. But I knew I had screwed up previous tests; so I decided to eliminate my rewire directive in NGINX and give it another go. That apparently was part of the problem with browser uploads…that or I made a change in a file I forgot about. After ditching the directive; the browser upload was once again returning the file names. I flipped the directive on, I flipped it off; and the behavior was broken on and working off.
I thought I had checked that; I thought I had checked that 20 times. I guess I checked it during the auth stuff and assumed the browser problem was related. It wasn’t; it was releated to the damn rewrite.
So…I’m owning up to my stupidity; but at least I have that working. Now..on to something else.
Moving linx-server to a path also meant it changed the URL it returns to contain that path. This isn’t what I want since this new configuration is just serving images from wwwroot. The first setup worked because I had a redirect in nginx to capture all image requests to domain-root and serve those from the image directory. Ok, let’s just hard-code that the source.
This was where I thought this change had broken things; because I apparently did not test things as well as I thought. In fact, up until Tuesday night or so; I thought my mod was the sole thing that broke it. Turns out I just had too many changes I didn’t keep track of that left unknown variables breaking things; the nginx configuration is a prime example. But the confusing thing was the code mod worked fantastically on the mobile app. I was uploading images to a path’ed server and getting the exact URL I wanted.
So now with browser upload working, I found my one code mod returned exactly what I wanted when uploading an image. The second issue was that remote uploads done with ?url=remote were still returning a path’ed address. That’s because the response for that upload was generated elsewhere; so I just had to find that return and modify it with the hard coded URL.
End result? It works how I wanted. Gallery lives on main page; upload is on a non-listed path; images upload via all three methods and return the expected URL.
At some point I’ll do a fresh build on a server and carefully recreate each step to figure out exactly *what* breaks things without having 4 or 5 changes at once causing headaches.