kylepaulsen / ResourceOverride

An extension to help you gain full control of any website by redirecting traffic, replacing, editing, or inserting new content.
MIT License
468 stars 117 forks source link

404 only redirect #10

Open kyleladd opened 7 years ago

kyleladd commented 7 years ago

Perhaps you don't have all of the site's static assets (images,css,js,) on you local computer. With this, if the request header status code is a 404, you can redirect it to the production site. For me, our sites images and other uploaded user generated content is kept out of our repos. Therefore, when I clone the site's repo and create a local instance of the database, I don't have to copy all the various locations files are uploaded to my local computer nor have to create numerous resource override regex rules for the various resource url patterns. Instead, I just have something along the lines of `localsiteinstance.com->productionsiteinstance.com*` and apply to 404s only. image

After using these modifications for a couple months, the only issue at the moment that I've noticed is having it redirect json requests that are 404s. They do redirect, but I'm not applying CORS header (yet) and the browser's security blocks it. For the moment, I'm getting around the CORS issue with https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi Not sure if the cors header should be applied automatically by ResourceOverride. After all, there would be security implications for the users and I didn't want to introduce those yet. In order to address it in the future though, perhaps an additional toggle that they'll have to enable to disable cors for the applied regex on by modifying the headers OnHeadersReceived?

kyleladd commented 7 years ago

(And now I notice Resource Override handles modifying headers - CORS is even a preset - wow.) I will try this for the ajax CORS issue next time I encounter it. Sweet!!!

kylepaulsen commented 7 years ago

Hey, thanks for the PR. I'm not sure I fully understand how it works though. So is it like, you have a dev environment, but you might not have all the resources, and so if your local server hits a 404, redirect it to the production url? It seems like you could have some url rules to accomplish the same thing without checking for a 404 but maybe it's more complicated than that.

For example, if www.prod.com/images exists but your local env doesn't have the images folder, you could just do *localhost*/images/ --> http://www.prod.com/images/ I assume you already knew that though, so maybe it's more complicated.

You can make exception cases out of rules by putting them higher up.. maybe that would help?

  1. *localhost*/scripts/in_dev_env.js --> *localhost*/scripts/in_dev_env.js
  2. *localhost*/scripts/ --> http://www.prod.com/scripts/

in this case, all scripts EXCEPT in_dev_env.js will get redirected (as it is redirected to itself). Otherwise all other scripts are redirected to the prod env.

Anyway, I would like to know more about the use case for this feature. One of the difficult parts about this extension is keeping it simple and easy to understand for everyone, so I'm hesitant to introduce a new UI element for a specific use case. However, it's possible that this functionality is sorely missing from Resource Override. Thanks again for the PR. It shows someone out there cares.

kyleladd commented 7 years ago

I'm sure the same can be accomplished by writing a bunch of rules and exceptions. I just have it so I can switch between clients' sites and not have to update numerous rules. Instead of browsing production and url rewriting to local, you're using local and rewriting to production if you don't have it (a development version). Essentially, it's the same thing but in the other direction and without having to write rules for everything you don't have locally - less rule configuration.

It's just an idea that i put out there because I've been using it for a while and perhaps someone else might find it useful or expand upon - whether it's merged or not. Regardless, this extension is awesome!!! I can actually browse my local and it resembles production without resources failing to load || copying each site entirely to local. Much appreciated.

kylepaulsen commented 7 years ago

I'll think on this. Maybe we can have an options button for url -> url which has more conditions for when it can apply.