Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Expo-Cli tunnel problem accessing with a different hostname (401 unauthorized) #1500

Closed
fritzZz opened this issue Jan 31, 2020 · 1 comment
Closed

Comments

@fritzZz
Copy link

fritzZz commented Jan 31, 2020

I'm using the command : expo start --tunnel to expose the web page to scan the QRCODE behind nginx.

Everything is working fine in localhost:19002, but behind NGINX using a different hostname (expo.mycompany.com) the ws connection (ws://expo.mycompany.com:19002/20ldcw_MHt3hl6t_ahe74XzAc1W5G7u40OpSN_Bi0qE/graphql) returns a 401 Unauthorized

I tried also putting in my /etc/hosts
127.0.0.1 myfakehost

and using myfakehost:19002 instead of localhost:19002 in local I get the same error 401.
that is something related to the exposure of the service on the tunnel with a different hostname.

To get a black page with the 401 error I used this approach :

Environment

ENV EXPO_DEVTOOLS_LISTEN_ADDRESS=0.0.0.0
ENV REACT_NATIVE_PACKAGER_HOSTNAME=expo.mycompany.com

expo diagnostics

Expo CLI 3.11.7 environment info:
System:
OS: Linux 4.14 Debian GNU/Linux 9 (stretch) 9 (stretch)
Shell: 4.4.12 - /bin/bash
Binaries:
Node: 10.18.1 - /usr/local/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
npmGlobalPackages:
expo-cli: 3.11.7

nginx version
nginx version: nginx/1.17.8

nginx.conf

map $http_upgrade $connection_upgrade{
        default upgrade;
        `` close;
}

upstream ws-expo {
        # enable sticky session based on IP
        #ip_hash;

        server expo-service:19002;
}

server {
    server_name expo.mycompany.com;
    listen 80;
    listen [::]:80;

    location / {
        proxy_pass http://expo-service:19002;
    }

}

server {
    server_name expo.mycompany.com;
    listen 19002;
    #listen [::]:19002;

    location / {
            #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #proxy_set_header Host $host;
            
            proxy_pass http://ws-expo;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
    }


}
@fritzZz
Copy link
Author

fritzZz commented Jan 31, 2020

Found a solution :

adding changing into the nginx.conf :

proxy_set_header Origin http://expo.mycompany.com:19002;

I found the right behavior into the dev-tools server

https://github.com/expo/expo-cli/blob/master/packages/dev-tools/server/DevToolsServer.js

And it considers also the port as part of the Host header to validate the client.

@fritzZz fritzZz closed this as completed Jan 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant