Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose and Magento 2 #368

Open
robbanl opened this issue Feb 16, 2023 · 1 comment
Open

Expose and Magento 2 #368

robbanl opened this issue Feb 16, 2023 · 1 comment

Comments

@robbanl
Copy link

robbanl commented Feb 16, 2023

Hello,

I haven't had time yet to look through the code, but I'll post an issue here as a start.

I work mainly with Laravel but also Magento 2. I tried today to create a tunnel for a Magento 2 site, using the command below. The site and components are running inside my local Docker environment, so http://127.0.0.1 will give the response.

expose share http://localhost --subdomain=mycustomsubdomain

The problem (one of them) with Magento is that you are required to input the store domain in the database. I set this to mycustomsubdomain.domain.tld. Visiting http://127.0.0.1 will then redirect me to mycustomsubdomain.domain.tld.

When I started the share, there was a redirect loop when visiting mycustomsubdomain.domain.tld. Checking the $_SERVER values I noticed that HTTP_HOST and SERVER_NAME was set to "localhost".

I haven't dug yet inside Magento 2, but as a quick fix, I added the following to lines inside index.php:

$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_ORIGINAL_HOST'];
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_X_ORIGINAL_HOST'];

And everything started to work as expected.

The reason I'm starting out here, is because using a competitor to expose.dev, you are just entering the port number (80 in my case) and it works out of the box.

@yob-yob
Copy link

yob-yob commented May 4, 2024

YOU ARE A LIFE SAVER!! @robbanl

I have been debugging this issue for 24 hours STRAIGHT!... THIS FIXED IT!...

$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_ORIGINAL_HOST'];
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_X_ORIGINAL_HOST'];

I had to add it in my wp-config.php file (IDK if this is a good idea but it works... and I also had to add some checks to make sure the key exists)

Modified Code Be...

if (array_key_exists('HTTP_X_ORIGINAL_HOST', $_SERVER)) {
	$_SERVER['HTTP_HOST'] =  $_SERVER['HTTP_X_ORIGINAL_HOST'];
}
if (array_key_exists('HTTP_X_ORIGINAL_HOST', $_SERVER)) {
	$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_X_ORIGINAL_HOST'];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants