Skip to content

Commit

Permalink
Fix prod socket and api routes for UI (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordojordo authored Nov 26, 2024
1 parent c80c6e6 commit 25204fd
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 197 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-lawndon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ jobs:
tags: |
ghcr.io/${{ github.repository_owner }}/lawndon-pi-server:${{ github.ref_name }}
ghcr.io/${{ github.repository_owner }}/lawndon-pi-server:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/lawndon-pi-server:latest
- name: Build and push UI image
uses: docker/build-push-action@v6
Expand All @@ -104,3 +105,4 @@ jobs:
tags: |
ghcr.io/${{ github.repository_owner }}/lawndon-pi-ui:${{ github.ref_name }}
ghcr.io/${{ github.repository_owner }}/lawndon-pi-ui:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/lawndon-pi-ui:latest
3 changes: 2 additions & 1 deletion pi/Dockerfile.ui
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ RUN pnpm build

# Runtime stage
FROM nginx:alpine
COPY --from=build /usr/src/app/ui/dist /usr/share/nginx/html
COPY --from=build /usr/src/app/ui/dist /app
COPY --from=build /usr/src/app/ui/nginx.conf /etc/nginx/nginx.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
4 changes: 1 addition & 3 deletions pi/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ services:
- app_network

ui:
image: ghcr.io/jordojordo/uwb-ui:latest
environment:
VITE_NODE_ENV: production
image: ghcr.io/jordojordo/lawndon-pi-ui:latest
ports:
- "80:80" # Expose UI
depends_on:
Expand Down
40 changes: 0 additions & 40 deletions pi/package.sh

This file was deleted.

2 changes: 1 addition & 1 deletion pi/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^5.0.0",
"@types/node": "^22.9.3",
"@types/node": "^22.10.0",
"eslint": "^9.15.0",
"globals": "^15.12.0",
"http-proxy-middleware": "^3.0.3",
Expand Down
54 changes: 27 additions & 27 deletions pi/server/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pi/ui/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_URL="http://localhost:5000"
3 changes: 1 addition & 2 deletions pi/ui/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// / <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_NODE_ENV: string;
readonly VITE_BACKEND_URL: string;
readonly VITE_API_URL: string;
readonly BASE_URL: string;
readonly PROD: boolean
}
Expand Down
22 changes: 21 additions & 1 deletion pi/ui/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,20 @@ http {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
add_header Access-Control-Allow-Headers "Authorization, Content-Type, X-Requested-With";

# Handle preflight requests
if ($request_method = 'OPTIONS') {
return 204;
}

access_log /var/log/nginx/api_access.log main;
}

location /ws/ {
location /socket.io/ {
proxy_pass http://server:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
Expand All @@ -52,6 +62,16 @@ http {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
add_header Access-Control-Allow-Headers "Authorization, Content-Type, X-Requested-With";

# Handle preflight requests
if ($request_method = 'OPTIONS') {
return 204;
}

access_log /var/log/nginx/websocket_access.log main;
}

Expand Down
10 changes: 4 additions & 6 deletions pi/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@
"dev": "NODE_ENV=development vite",
"build": "vue-tsc --build --force && vite build",
"preview": "vite preview",
"lint": "eslint . --fix",
"format": "prettier --write src/"
"lint": "eslint . --fix"
},
"dependencies": {
"d3": "^7.9.0",
"pinia": "^2.2.6",
"socket.io-client": "^4.8.1",
"vue": "^3.5.13",
"vue-router": "^4.4.5"
"vue-router": "^4.5.0"
},
"devDependencies": {
"@tsconfig/node22": "^22.0.0",
"@types/d3": "^7.4.3",
"@types/node": "^22.9.3",
"@types/node": "^22.10.0",
"@vitejs/plugin-vue": "^5.2.0",
"@vue/eslint-config-prettier": "^10.1.0",
"@vue/eslint-config-typescript": "^14.1.3",
"@vue/eslint-config-typescript": "^14.1.4",
"@vue/tsconfig": "^0.6.0",
"eslint": "^9.15.0",
"eslint-plugin-vue": "^9.31.0",
"npm-run-all2": "^7.0.1",
"prettier": "^3.3.3",
"typescript": "~5.6.3",
"vite": "^5.4.11",
"vite-plugin-vue-devtools": "^7.6.4",
Expand Down
Loading

0 comments on commit 25204fd

Please sign in to comment.