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

next: support dev #85

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Caddyfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
debug
}

localhost {
tls internal
http://localhost {
encode gzip
handle_path /api/* {
reverse_proxy meshinfo:9000
}
handle_path /next/* {
rewrite * /next{uri}
reverse_proxy frontend:80
reverse_proxy frontend:5173
}
handle /* {
root * /srv
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile.spa
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ COPY . .

WORKDIR /frontend

ARG env=production
ENV NODE_ENV=$env

RUN corepack enable
RUN yarn
RUN yarn build --base=/next/

EXPOSE 80

CMD ["/frontend/scripts/run-frontend.sh"]
CMD ["/frontend/scripts/run-frontend.sh"]
18 changes: 18 additions & 0 deletions Dockerfile.spa.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# trunk-ignore-all(checkov/CKV_DOCKER_3)
FROM node:20.11.1-alpine

LABEL org.opencontainers.image.source="https://github.com/MeshAddicts/meshinfo"
LABEL org.opencontainers.image.description="Realtime web UI to run against a Meshtastic regional or private mesh network."

COPY . .

WORKDIR /frontend

ENV NODE_ENV=dev

RUN corepack enable
RUN yarn

EXPOSE 5173

CMD ["/frontend/scripts/run-frontend.sh"]
1 change: 1 addition & 0 deletions api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ async def server_config(request: Request) -> JSONResponse:
app.add_middleware(
CORSMiddleware,
allow_origins=allow_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)
Expand Down
18 changes: 8 additions & 10 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ services:
caddy:
image: caddy:latest
ports:
- 8001:80
- 8443:443
- 8000:80
volumes:
- ./caddy/data:/data/caddy
- ./Caddyfile.dev:/etc/caddy/Caddyfile
Expand Down Expand Up @@ -35,12 +34,12 @@ services:
frontend:
build:
context: .
dockerfile: Dockerfile.spa
dockerfile: Dockerfile.spa.dev
ports:
- 8000:80
- 5173:5173
environment:
- VITE_API_BASE_URL=/api
- NODE_ENV=production
- VITE_API_BASE_URL=http://localhost:9000
- NODE_ENV=dev
restart: always

meshinfo:
Expand All @@ -52,12 +51,11 @@ services:
- ./output:/app/output
- ./templates:/app/templates
- ./spa:/app/spa
ports:
- 9000:9000
environment:
- PYTHONUNBUFFERED=1
- MQTT_HOST=mqtt
- MQTT_PORT=1883
- MQTT_USERNAME=meshinfo
- MQTT_PASSWORD=m3sht4st1c
- ALLOW_ORIGINS=*
restart: always
depends_on:
- caddy
Expand Down
4 changes: 0 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ services:
- ./output:/app/output
environment:
- PYTHONUNBUFFERED=1
- MQTT_HOST=mqtt
- MQTT_PORT=1883
- MQTT_USERNAME=meshinfo
- MQTT_PASSWORD=m3sht4st1c
ports:
- 9000:9000
restart: always
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"start": "vite",
"dev": "vite dev",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
Expand Down
8 changes: 7 additions & 1 deletion frontend/scripts/run-frontend.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
echo "NODE_ENV: " $NODE_ENV
echo "API BASE URL: " $VITE_API_BASE_URL
yarn build --base=/next/ && npx pm2-runtime /frontend/scripts/server.js

if [ "$NODE_ENV" == "dev" ]; then
yarn run dev --host 0.0.0.0
else
yarn build --base=/next/ && npx pm2-runtime /frontend/scripts/server.js
fi
2 changes: 1 addition & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
server: {
proxy: {
"/api": {
target: process.env.API_BASE_URI ?? "http://localhost:9000",
target: process.env.VITE_API_BASE_URL ?? "http://localhost:9000",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
Expand Down
Loading