Run expo web on custom port?

Would be nice to run expo web on port 80 on my web server

Hi

It’s generally not a good idea to allow the general Internet to access a development server, so I would be hesitant to run expo start --web on port 80 on a publicly available Web server.

Could you elaborate on why you would like to do this?

Was tossing up this site for fun

It’s serving our expo build:web from a node server which is also our API server

Thought it would’ve been a faster workflow for our project for me to “test in prod” our expo web as I was working on it. Essentially if going to that site was serving the hot-reloading webpack devserver. Both for me and also for friends, as I could give them a link to this collaborative/realtime project and hot reload it as they use it.

(The alternative is me developing on my laptop, running expo build:web, copying it to the backend, restarting our backend, making sure people refresh the website)

Wound up using sudo socat tcp-listen:80,reuseaddr,fork tcp:localhost:19006 to proxy requests to the dev server. I couldn’t get the webpack devserver proxy to send things to the node API though. I think it might’ve been that I was using the full host (with port) instead of just the hostname (no port) to connect to the websocket API, but the code’s changed since then so not sure :thinking:

1 Like

Ah.

Well, I see that packages/xdl/src/Webpack.ts in the expo-cli source code contains the following line:

export const DEFAULT_PORT = getenv.int('WEB_PORT', 19006);

so I would guess that setting the WEB_PORT environment variable to 80 might work. However you’d need to run expo start --web as root in order to be able to bind to a low port.

I think it might be best to have some sort of automated way to deploy/restart and maybe something based on setInterval() to check for updates and call location.reload() if necessary? Or display a “Reload” button.

1 Like

Yes - using something like this overrides the port for web successfully

WEB_PORT=9000 expo start:web --https

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.