Skip to content

Commit 7337fbf

Browse files
author
Libish Murugesan
committed
Add deploy config and env-based API base
1 parent 9edb475 commit 7337fbf

File tree

5 files changed

+76
-5
lines changed

5 files changed

+76
-5
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Deploy Frontend
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'topologicpy-web-frontend/**'
8+
- '.github/workflows/deploy-frontend.yml'
9+
10+
permissions:
11+
contents: read
12+
pages: write
13+
id-token: write
14+
15+
concurrency:
16+
group: 'pages'
17+
cancel-in-progress: true
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
defaults:
23+
run:
24+
working-directory: topologicpy-web-frontend
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-node@v4
28+
with:
29+
node-version: '20'
30+
cache: 'npm'
31+
cache-dependency-path: topologicpy-web-frontend/package-lock.json
32+
- name: Install
33+
run: npm ci
34+
- name: Build
35+
env:
36+
BASE_PATH: '/${{ github.event.repository.name }}/'
37+
VITE_API_BASE: 'https://YOUR-BACKEND.onrender.com'
38+
run: npm run build
39+
- name: Upload artifact
40+
uses: actions/upload-pages-artifact@v3
41+
with:
42+
path: topologicpy-web-frontend/dist
43+
44+
deploy:
45+
needs: build
46+
runs-on: ubuntu-latest
47+
environment:
48+
name: github-pages
49+
url: ${{ steps.deployment.outputs.page_url }}
50+
steps:
51+
- id: deployment
52+
uses: actions/deploy-pages@v4

topologicpy-web-backend/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt ./
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
RUN pip install --no-cache-dir ifcopenshell topologicpy
8+
9+
COPY app ./app
10+
11+
EXPOSE 8000
12+
13+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

topologicpy-web-backend/app/main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@
4040
version="0.1.0",
4141
)
4242

43+
cors_origins = [
44+
"http://localhost:5173",
45+
"http://127.0.0.1:5173",
46+
]
47+
extra_origins = os.getenv("CORS_ORIGINS", "")
48+
if extra_origins:
49+
cors_origins.extend([o.strip() for o in extra_origins.split(",") if o.strip()])
50+
4351
app.add_middleware(
4452
CORSMiddleware,
45-
allow_origins=[
46-
"http://localhost:5173",
47-
"http://127.0.0.1:5173",
48-
],
53+
allow_origins=cors_origins,
4954
allow_credentials=True,
5055
allow_methods=["*"],
5156
allow_headers=["*"],

topologicpy-web-frontend/src/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import TopologyViewer from "./TopologyViewer.jsx";
55
import "./App.css";
66
import logoImg from "./assets/topologicStudio-white-logo400x400.png";
77

8-
const API_BASE = "http://localhost:8000"; // FastAPI backend
8+
const API_BASE = import.meta.env.VITE_API_BASE || "http://localhost:8000"; // FastAPI backend
99

1010
export default function App() {
1111
const spinnerStyle = { __html: `@keyframes spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }` };

topologicpy-web-frontend/vite.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ import react from '@vitejs/plugin-react'
44
// https://vite.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7+
base: process.env.BASE_PATH || '/',
78
})

0 commit comments

Comments
 (0)