Change the url of the backend but not the client one using Varnish - url

I want to manipulate the client url "www.example.com/download.." to "one.other.com/download...
But I want that the url on the client maintain the first "www.example.com/download"
Is there any way with Varnish 3 to do this??

Yes, you can easily do it using the regsub() function in VCL in vcl_recv.
For instance:
if (req.http.host ~ "^(www\.)?example\.com" && req.url~ "^/download/") {
set req.http.host = "one.other.com";
set req.url = regsub(req.url, "^/download/", "/");
}
This examples rewrites access to http://www.example.com/download/example.jpg to http://one.other.com/example.jpg. Of course, it is not visible to the user.

Related

Durable Id assignment in URL not working in lightning

Problem Statement: To auto-populate the lookup field I use durable Id assignment with name. For e.g. https://sales--dev.my.salesforce.com/m2p/e?CF00N0l0000051XXX=Contract-00000XXX&inline=1
Notice this -> CF00N0l0000051XXX=Contract-00000XXX ~ durableId=recordName In url.
Now, when the user clicks the New button to create a record on the VF page above URL is loaded in classic and populates the Name in lookup like this
Trying to solve: In lightning, URL is getting overridden by this URL
https://sales--dev.lightning.force.com/lightning/o/objectName/new?count=2 Is there a way to achieve the same URL in lightning?
Do you really need it to be an URL hack? Can'y your thing be a quick action? The url prepopulation would be more reliable there and work everywhere.
URL hacking in lightning is bit simpler, you use field API names instead of IDs. These are decent tutorial: https://www.salesforceben.com/salesforce-url-hacking-for-lightning-tutorial/, https://sfdcdevelopers.com/2020/02/26/url-trick-in-salesforce-lightning/
So, how do you know where you are, in Classic or LEX. Which URL to use? Have a look at UiThemeDisplayed variable, available in Visualforce and in Apex's UserInfo class.
IF($User.UIThemeDisplayed == 'Theme4d' || $User.UIThemeDisplayed == 'Theme4t' || $User.UIThemeDisplayed == 'Theme4u',
'link for lightning',
'link for classic'
)
Working approach:
Created a controller for VF page:
global PageReference newParty() {
PageReference pageRef;
pageRef = new PageReference('/lightning/o/Party/new?defaultFieldValues=Contract='+contractID);
return pageRef
You can absolutely do this with a button / URL hack in lightning with the Spring '20 release. The URL can use "defaultFieldValues="
https://www.salesforceben.com/salesforce-url-hacking-for-lightning-tutorial/

Change the browser URL bar text

I own a domain in a hosting provider (just the domain). This domain is pointing to another web address:
domain.com-->anotherdomain.dom/path
In another side, I have added my domain to my Cloudflare account, like this:
domain.com-->Cloudflare-->anotherdomain.dom/path
The issue is that after typing domain.dom, the URL text in the browser URL bar is anotherdomain.dom/path, and I need it to be domain.com.
Is it possible to have domain.com in the broswer URL bar? Do I have to write some code inside my .htaccess file or something inside anotherdomain.com? Do I have to do something inside Cloudflare (maybe with "workers")?
It sounds like currently, your domain domain.com is set up as a redirect. When a user visits domain.com in their browser, the server (Cloudflare) responds with a message saying: "Please go to anotherdomain.com/path instead." The browser then acts like the user actually typed anotherdomain.com/path in the address bar.
It sounds like what you want instead is for domain.com to be a proxy. When a request comes in for domain.com, you want Cloudflare to fetch the content from anotherdomain.com/path and then return that content in response to the original request.
In order to do this, you will need to use Workers. Cloudflare Workers allows you to write arbitrary JavaScript code to tell Cloudflare how to handle HTTP requests for your domain.
Here's a Worker script that implements the proxy behavior that you want:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
// Parse the original request URL.
let url = new URL(request.url);
// Change domain name.
url.host = "anotherdomain.org";
// Add path prefix.
url.pathname = "/path" + url.pathname;
// Create a new request with the new URL, but
// copying all other properties from the
// original request.
request = new Request(url, request);
// Send the new request.
let response = await fetch(request);
// Use the response to fulfill the original
// request.
return response;
}

Silex 2.0 Redirection

I'm a Silex newbie and I'd like to redirect the '/' url to the default language like '/en' for example. I do this :
$app->match('/', function(Application $app){
return $app->redirect('/Silex/www/'.$app['locale_fallbacks'][0]);
});
Am I constrained to put the absolute url from the root of the server ? I'd like to put only $app->redirect('$app['locale_fallbacks'][0]);. And is it the right way to get the default language ?
Thanks a lot
You do not have to give the host there. As in your match() you will pass a relative url. However it would probably be better not to make a new roundtrip to the browser and to forward the request internally or even rewrite it via .htaccess.
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
$app->match('/', function () use ($app) {
$subRequest = Request::create('/' . $app['locale_fallbacks'][0], 'GET');
return $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
});

Contao: How can I change the protocol of the base url?

In Contao 3.5.9
I have uploaded to new server and am using a different domain from the original installation. I am also using https://
Many of the resources needed are not being loaded because the system has the base url set to http://
It is using the correct domain name in the base url, but the wrong protocol.
I cannot login to the admin.
I searched Google (not much there about Contao) and found this: http://blog.qzminski.com/article/move-the-contao-to-another-server.html
reading it, it seems that the base url is set in the admin, which means it can be found somewhere in the db.
I have search the DB dump but cannot find it.
How can I change the protocol of the base url?
Contao uses the following to determine whether the current request is done via SSL or not ยป \Environment::get('ssl'):
/**
* Return true if the current page was requested via an SSL connection
*
* #return boolean True if SSL is enabled
*/
protected static function ssl()
{
return ($_SERVER['SSL_SESSION_ID'] || $_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1);
}
It is possible that your server environment does not set either of these $_SERVER globals. This can be the case if you are using an SSL proxy for example.
If that is the case for you, then you can extend the SSL detection by inserting
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'])
{
$_SERVER['HTTPS'] = 1;
}
into your /system/config/initconfig.php. See https://github.com/contao/core/issues/7542 for example (only German though).

rails responding to cross domain request developing locally, spotify app development

So Im messing around with developing a spotify app, trying to get it to talk to my local rails application API. I cant get anything other than a req.status 0 when I try it.
I think its either a problem with the spotify manifest.json file, not allowing the port:3000 to go on the url you set in required permissions, but it also says the following in their documentation.
https://developer.spotify.com/technologies/apps/tutorial/
If you need to talk to an outside web API you're welcome to, as long as you abide by the rules set in the Integration Guidelines. Please note that when talking with a web API, the requests will come from the origin sp://$APPNAME (so sp://tutorial for our example) - make sure the service you are talking to accepts requests from such an origin.
So, Im not sure if rails is set to not allow this sort of thing, or if its an issue with the putting the port into the required permissions, but my request
var req = new XMLHttpRequest();
req.open("GET", "http://127.0.0.1:3000/api/spotify/track/1.json", true);
console.log(req);
req.onreadystatechange = function() {
console.log(req.status);
console.log(req.readyState);
if (req.readyState == 4) {
if (req.status == 200) {
console.log("Search complete!");
console.log(req.responseText);
}
}
};
req.send();
Always returns status 0 where as their example:
var req = new XMLHttpRequest();
req.open("GET", "http://ws.audioscrobbler.com/2.0/?method=geo.getevents&location=" + city + "&api_key=YOUR_KEY_HERE", true);
req.onreadystatechange = function() {
console.log(req.status);
if (req.readyState == 4) {
console.log(req);
if (req.status == 200) {
console.log("Search complete!");
console.log(req.responseText);
}
}
};
req.send();
Will return a 403 response at least. its like the request is not being made or something?
Anyone have any idea what might be going on?
Much appreciated!
When talking to external services from a Spotify App, even if they're running on your local machine, you need to make sure that two things are in place correctly:
The URL (or at least the host) is in the RequiredPermissions section of your manifest. Port doesn't matter. http://127.0.0.1 should be fine for your case.
The server is allowing the sp://your-app-id origin for requests, as noted in the documentation you pasted in your question. This is done by setting the Access-Control-Allow-Origin header in your service's HTTP response. People often set it to Access-Control-Allow-Origin: * to allow anything to make requests to their service.
Thanks for help, I got it figured out, I think it was multiple things, with one main Im an idiot moment for not trying that earlier
First off, I had to run rails on port 80, as obviously if Im accessing my site from 127.0.0.1:3000, thats not going to work if spotify app is requesting 127.0.0.1 unless I can load that directly in the browser, which you cannot unless you run on 80. That is done via
rvmsudo rails server -p 80
Need to use rvmsudo because changing port requires permissions.
Next I had to set access controll allow origin as noted above, that can be done in rails 3 by adding before filter to your app controller as follows.
class ApplicationController < ActionController::Base
logger.info "I SEE REQUEST"
before_filter :cor
def cor
headers["Access-Control-Allow-Origin"] = "*"
headers["Access-Control-Allow-Methods"] = %w{GET POST PUT DELETE}.join(",")
headers["Access-Control-Allow-Headers"] = %w{Origin Accept Content-Type X-Requested-With X-CSRF-Token}.join(",")
head(:ok) if request.request_method == "OPTIONS"
end
end
Finally, and most importantly (sigh), you cant just righclick and reload your spotify app when you make changes to your manifest file, exit spotify completely and restart it!

Resources