Skip to content

Commit 0dae1bb

Browse files
authored
Merge pull request #52 from splitly25/deploy2
check
2 parents 7f80c43 + 1982e8a commit 0dae1bb

10 files changed

Lines changed: 1180 additions & 27 deletions

File tree

.github/workflows/deploy-api.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Deploy Splitly API to VPS
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'api/**'
9+
workflow_dispatch:
10+
11+
jobs:
12+
deploy:
13+
name: Deploy to Production Server
14+
runs-on: ubuntu-latest
15+
16+
# ADD THIS SECTION ⬇️
17+
permissions:
18+
deployments: write
19+
contents: read
20+
statuses: write
21+
22+
environment:
23+
name: production-api
24+
url: https://splitly.be.khangdev.me
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
30+
- name: Start Deployment
31+
uses: bobheadxi/deployments@v1
32+
id: deployment
33+
with:
34+
step: start
35+
token: ${{ secrets.GITHUB_TOKEN }}
36+
env: production-api
37+
ref: ${{ github.sha }} # ADD THIS LINE
38+
39+
- name: Deploy to VPS via SSH
40+
uses: appleboy/ssh-action@v1.0.0
41+
with:
42+
host: ${{ secrets.VPS_HOST }}
43+
username: ${{ secrets.VPS_USERNAME }}
44+
key: ${{ secrets.VPS_SSH_KEY }}
45+
port: 22
46+
script: |
47+
# Navigate to project directory
48+
cd ~/splitly/api
49+
50+
# Pull latest changes
51+
git pull origin main
52+
53+
# Install dependencies
54+
npm install
55+
56+
# Build the project
57+
npm run build
58+
59+
# Restart PM2 (with fallback if process doesn't exist)
60+
pm2 restart splitly-api || PORT=8017 pm2 start npm --name "splitly-api" -- run production
61+
62+
# Save PM2 config
63+
pm2 save
64+
65+
# Show status
66+
pm2 status
67+
68+
echo "✅ Deployment completed successfully!"
69+
70+
- name: Update Deployment Status
71+
uses: bobheadxi/deployments@v1
72+
if: always()
73+
with:
74+
step: finish
75+
token: ${{ secrets.GITHUB_TOKEN }}
76+
status: ${{ job.status }}
77+
env: production-api
78+
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
79+
env_url: https://splitly.be.khangdev.me

.github/workflows/deploy-web.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Deploy Splitly Web to VPS
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'web/**'
9+
workflow_dispatch:
10+
11+
jobs:
12+
deploy:
13+
name: Deploy Web to Production Server
14+
runs-on: ubuntu-latest
15+
16+
permissions:
17+
deployments: write
18+
contents: read
19+
statuses: write
20+
21+
environment:
22+
name: production-web
23+
url: https://splitly.khangdev.me
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Start Deployment
30+
uses: bobheadxi/deployments@v1
31+
id: deployment
32+
with:
33+
step: start
34+
token: ${{ secrets.GITHUB_TOKEN }}
35+
env: production-web
36+
ref: ${{ github.sha }}
37+
38+
- name: Deploy Web to VPS via SSH
39+
uses: appleboy/ssh-action@v1.0.0
40+
with:
41+
host: ${{ secrets.VPS_HOST }}
42+
username: ${{ secrets.VPS_USERNAME }}
43+
key: ${{ secrets.VPS_SSH_KEY }}
44+
port: 22
45+
script: |
46+
# Navigate to project directory
47+
cd ~/splitly/web
48+
49+
# Pull latest changes
50+
git pull origin main
51+
52+
# Install dependencies
53+
npm install
54+
55+
# Build the project
56+
npm run build
57+
58+
# Copy built files to nginx directory
59+
sudo cp -r dist/* /var/www/splitly/
60+
sudo chown -R www-data:www-data /var/www/splitly
61+
62+
# Restart PM2 web process (with fallback if process doesn't exist)
63+
pm2 restart splitly-web || pm2 start npm --name "splitly-web" -- run preview -- --port 3001
64+
65+
# Save PM2 config
66+
pm2 save
67+
68+
# Show status
69+
pm2 status
70+
71+
# Test nginx configuration and reload
72+
sudo nginx -t && sudo systemctl reload nginx
73+
74+
echo "✅ Web deployment completed successfully!"
75+
76+
- name: Update Deployment Status
77+
uses: bobheadxi/deployments@v1
78+
if: always()
79+
with:
80+
step: finish
81+
token: ${{ secrets.GITHUB_TOKEN }}
82+
status: ${{ job.status }}
83+
env: production-web
84+
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
85+
env_url: https://splitly.khangdev.me

api/src/config/cors.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
/**
2-
* CORS Configuration
3-
*/
1+
import { WHITELIST_DOMAINS } from '~/utils/constants'
2+
import { env } from '~/config/environment'
3+
import { StatusCodes } from 'http-status-codes'
4+
import ApiError from '~/utils/ApiError'
45

6+
// CORS Options Configuration
57
export const corsOptions = {
6-
origin: [
7-
'http://localhost:5173', // Vite dev server
8-
'http://localhost:3000', // React dev server alternative
9-
'http://127.0.0.1:5173',
10-
'http://127.0.0.1:3000'
11-
],
12-
credentials: true, // Allow credentials (cookies, authorization headers, etc.)
13-
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
14-
allowedHeaders: [
15-
'Origin',
16-
'X-Requested-With',
17-
'Content-Type',
18-
'Accept',
19-
'Authorization',
20-
'Cache-Control'
21-
],
22-
optionsSuccessStatus: 200 // Some legacy browsers (IE11, various SmartTVs) choke on 204
23-
}
8+
origin: function (origin, callback) {
9+
// if origin is undefined in dev mode pass the CORS
10+
if (env.BUILD_MODE === 'dev') {
11+
return callback(null, true)
12+
}
13+
14+
// Check if the origin is in the whitelist
15+
if (WHITELIST_DOMAINS.includes(origin)) {
16+
return callback(null, true)
17+
}
18+
19+
// If the domain is not allowed, return an error
20+
return callback(new ApiError(StatusCodes.FORBIDDEN, `${origin} not allowed by our CORS Policy.`))
21+
},
22+
optionsSuccessStatus: 200,
23+
24+
// CORS will allow receiving cookies from requests
25+
credentials: true,
26+
}

api/src/utils/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { env } from '~/config/environment'
22

3-
export const WHITELIST_DOMAINS = ['http://localhost:5173', 'https://your-production-domain.com']
3+
export const WHITELIST_DOMAINS = ['http://localhost:5173', 'https://splitly.khangdev.me']
44

55
export const BILL_TYPE = ['equal', 'item-based', 'people-based']
66

web/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"build": "vite build",
99
"lint": "eslint .",
1010
"preview": "vite preview",
11-
"host": "vite --host"
11+
"host": "vite --host",
12+
"production": "cross-env NODE_ENV=production vite build"
1213
},
1314
"dependencies": {
1415
"@emotion/react": "^11.14.0",

web/src/App.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import BillDetail from './pages/Bills/BillDetail'
1515
import Group from './pages/Groups/Group'
1616
import Payment from './pages/Payment/Payment'
1717
import PaymentSuccess from './pages/Payment/PaymentSuccess'
18+
import GroupDetails from './pages/Groups/GroupDetails'
1819

1920
const ProtectedRoute = ({ user }) => {
2021
if (!user) return <Navigate to="/login" replace={true} />
@@ -30,7 +31,7 @@ function App() {
3031
<Route element={<ProtectedRoute user={currentUser} />}>
3132
<Route path="/dashboard" element={<Dashboard />} />
3233
<Route path="/groups" element={<Group />} />
33-
{/* <Route path="/groups/:groupId" element={<GroupDetail />} /> */}
34+
<Route path="/groups/:groupId" element={<GroupDetails />} />
3435
<Route path="/history" element={<History />} />
3536
<Route path="/debt" element={<Debt />} />
3637
<Route path="/boards/:boardId" element={<Board />} />

web/src/components/Group/GroupCard.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function GroupCard({ group, onClick, onDelete }) {
7878
},
7979
}}
8080
>
81-
<Delete sx={{ fontSize: '18px' }} />
81+
<Delete sx={{ fontSize: '22px' }} />
8282
</IconButton>
8383
</Box>
8484
</Box>

0 commit comments

Comments
 (0)