Skip to content

Commit 7822b59

Browse files
Update
1 parent 3cb60fb commit 7822b59

15 files changed

Lines changed: 106 additions & 44 deletions

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
node_modules/
2+
dist/
3+
.DS_Store
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
9+
# Local env files
10+
.env
11+
.env.*
12+
13+
# TypeScript incremental build output
14+
*.tsbuildinfo

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ RUN npm run build
1010

1111
FROM nginx:1.29-alpine
1212

13-
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
13+
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf.template
1414
COPY docker/entrypoint.sh /docker-entrypoint-learn-mobile-preview.sh
1515
COPY --from=build /app/dist /usr/share/nginx/html
1616

1717
RUN chmod +x /docker-entrypoint-learn-mobile-preview.sh
1818

19-
EXPOSE 80
19+
EXPOSE 3000
2020

2121
ENTRYPOINT ["/docker-entrypoint-learn-mobile-preview.sh"]

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ The app does not emulate native APIs. Expo handles the runtime; this project onl
66

77
## Local Development
88

9-
Start your Expo web app on port `3000`, then run:
9+
Start your Expo web app on port `3001`, then run:
1010

1111
```bash
1212
npm install
1313
npm run dev
1414
```
1515

16-
Open the wrapper at `http://localhost:5173`. It defaults to loading `http://localhost:3000`.
16+
Open the wrapper at `http://localhost:3000`. It defaults to loading Expo web through `/__expo_preview/`.
17+
18+
To target a different local Expo web URL:
19+
20+
```bash
21+
EXPO_WEB_URL="http://localhost:3002" npm run dev
22+
```
1723

1824
## Docker
1925

@@ -26,15 +32,15 @@ docker build -t learn_mobile-preview .
2632
Run it:
2733

2834
```bash
29-
docker run --rm -p 8080:80 learn_mobile-preview
35+
docker run --rm -p 3000:3000 learn_mobile-preview
3036
```
3137

32-
Open `http://localhost:8080`. The phone iframe will point at `http://localhost:3000` by default.
38+
Open `http://localhost:3000`. The phone iframe points at `/__expo_preview/`, which nginx proxies to Expo web at `http://localhost:3001` by default. In Docker, that default only works when Expo is reachable from the sidecar as `localhost:3001`.
3339

3440
To target a different Expo web URL:
3541

3642
```bash
37-
docker run --rm -p 8080:80 -e PREVIEW_URL="http://localhost:3000" learn_mobile-preview
43+
docker run --rm -p 3000:3000 -e EXPO_WEB_URL="http://host.docker.internal:3001" learn_mobile-preview
3844
```
3945

4046
## Container Registry

dist/assets/index-CsjKjlQs.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/assets/index-DOD3Vl8z.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

dist/config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

dist/config.template.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

dist/index.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

docker/entrypoint.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/bin/sh
22
set -eu
33

4-
: "${PREVIEW_URL:=http://localhost:3000}"
4+
: "${PREVIEW_URL:=/__expo_preview/}"
5+
: "${EXPO_WEB_URL:=http://localhost:3001}"
6+
7+
envsubst '${EXPO_WEB_URL}' \
8+
< /etc/nginx/conf.d/default.conf.template \
9+
> /etc/nginx/conf.d/default.conf
510

611
envsubst '${PREVIEW_URL}' \
712
< /usr/share/nginx/html/config.template.js \

docker/nginx.conf

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,47 @@
11
server {
2-
listen 80;
2+
listen 3000;
33
server_name _;
44
root /usr/share/nginx/html;
55
index index.html;
66

7+
location = / {
8+
try_files /index.html =404;
9+
}
10+
11+
location = /index.html {
12+
try_files /index.html =404;
13+
}
14+
15+
location = /config.js {
16+
try_files /config.js =404;
17+
}
18+
19+
location = /__mobile_preview_assets/config.js {
20+
try_files /config.js =404;
21+
}
22+
23+
location /__mobile_preview_assets/ {
24+
try_files $uri =404;
25+
}
26+
27+
location /__expo_preview/ {
28+
rewrite ^/__expo_preview/?(.*)$ /$1 break;
29+
proxy_http_version 1.1;
30+
proxy_set_header Host $proxy_host;
31+
proxy_set_header Upgrade $http_upgrade;
32+
proxy_set_header Connection "upgrade";
33+
proxy_pass ${EXPO_WEB_URL};
34+
}
35+
736
location / {
8-
try_files $uri $uri/ /index.html;
37+
try_files $uri @expo_web;
38+
}
39+
40+
location @expo_web {
41+
proxy_http_version 1.1;
42+
proxy_set_header Host $proxy_host;
43+
proxy_set_header Upgrade $http_upgrade;
44+
proxy_set_header Connection "upgrade";
45+
proxy_pass ${EXPO_WEB_URL};
946
}
1047
}

0 commit comments

Comments
 (0)