Skip to content

Commit a8480ec

Browse files
committed
test
1 parent 67a23bd commit a8480ec

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

.github/workflows/ci.yml

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,40 @@ jobs:
3030
--health-retries 10
3131
3232
steps:
33+
# Step 1: Checkout code
3334
- name: Checkout code
3435
uses: actions/checkout@v2
3536
with:
3637
fetch-depth: 0 # Fetch all history for all branches and tags
3738

38-
# Set up Node.js environment
39+
# Step 2: Set up Node.js environment
3940
- name: Set up Node.js
4041
uses: actions/setup-node@v2
4142
with:
4243
node-version: "16"
4344

44-
# Install server dependencies
45+
# Step 3: Cache server dependencies
46+
- name: Cache server dependencies
47+
id: server-cache
48+
uses: actions/cache@v2
49+
with:
50+
path: ./server/node_modules
51+
key: ${{ runner.os }}-server-${{ hashFiles('./server/package-lock.json') }}
52+
restore-keys: |
53+
${{ runner.os }}-server-
54+
55+
# Step 4: Install server dependencies (if not cached)
4556
- name: Install server dependencies
4657
working-directory: ./server
4758
run: npm install
59+
if: steps.server-cache.outputs.cache-hit != 'true'
4860

49-
# Start the Express backend
61+
# Step 5: Start the Express backend
5062
- name: Start Express backend
5163
working-directory: ./server
5264
run: npm start & # Use '&' to run it in the background
5365

54-
# Wait for Express server to be ready
66+
# Step 6: Wait for Express server to be ready
5567
- name: Wait for Express server to be ready
5668
run: |
5769
echo "Waiting for Express server to be ready..."
@@ -64,20 +76,17 @@ jobs:
6476
sleep 5
6577
done
6678
67-
# Install and test backend (server)
68-
- name: Install and test server
69-
working-directory: ./server
70-
env:
71-
PORT: ${{ secrets.PORT }}
72-
USER: ${{ secrets.USER }}
73-
HOST: 127.0.0.1
74-
DATABASE: ${{ secrets.DATABASE }}
75-
PASSWORD: ${{ secrets.PASSWORD }}
76-
DBPORT: 33306 # Match the changed port
77-
JWT_SECRET: ${{ secrets.JWT_SECRET }}
78-
run: npm test
79+
# Step 7: Cache client dependencies
80+
- name: Cache client dependencies
81+
id: client-cache
82+
uses: actions/cache@v2
83+
with:
84+
path: ./client/node_modules
85+
key: ${{ runner.os }}-client-${{ hashFiles('./client/package-lock.json') }}
86+
restore-keys: |
87+
${{ runner.os }}-client-
7988
80-
# Install and build frontend (client)
89+
# Step 8: Install and build frontend (React client)
8190
- name: Install and build client
8291
working-directory: ./client
8392
env:
@@ -88,13 +97,24 @@ jobs:
8897
run: |
8998
npm install
9099
npm run build
91-
mv ./dist ../server/public # Move built React files to the server's public directory
92100
93-
# Debug step: MySQL logs
101+
# Step 9: Move frontend build to server/public directory
102+
- name: Move frontend build to server/public
103+
run: |
104+
echo "Cleaning up existing public directory..."
105+
rm -rf ./server/public # Clean the public directory
106+
echo "Moving new build files to server/public..."
107+
mv ./client/dist ./server/public
108+
109+
# Step 10: Verify frontend build in server/public
110+
- name: Verify frontend build in server/public
111+
run: ls -la ./server/public
112+
113+
# Step 11: Debug step: MySQL logs
94114
- name: MySQL Logs
95115
run: docker logs $(docker ps -q --filter "ancestor=mysql:8.0")
96116

97-
# Deploy to Heroku (only if on the main branch and build was successful)
117+
# Step 12: Deploy to Heroku (frontend and backend together)
98118
- name: Deploy to Heroku
99119
if: github.ref == 'refs/heads/main' && success()
100120
env:

client/vite.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ export default defineConfig({
66
plugins: [react(), tsconfigPaths()],
77
build: {
88
sourcemap: true, // Enable source maps for easier debugging
9+
outDir: "../server/public", // Output built files directly to server/public
10+
emptyOutDir: true, // Clean the output directory before building
911
},
1012
});

server/server.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ if (isProduction) {
8282
const clientPath = path.resolve(__dirname, "../client/dist");
8383
app.use(express.static(clientPath));
8484

85-
// Define the root route to serve the index.html file
86-
app.get("/", (req, res) => {
87-
res.sendFile(path.join(clientPath, "index.html"));
88-
});
89-
90-
// Catch-all route for SPA
9185
app.get("*", (req, res) => {
9286
res.sendFile(path.join(clientPath, "index.html"));
9387
});

0 commit comments

Comments
 (0)