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

Adjusting structrue for deployment #5

Merged
merged 7 commits into from
Sep 20, 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
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: angular-build
path: ./frontend/dist/ # Path to Angular build files
path: ./frontend/dist/smetovi/ # Path to Angular build files

# --- Build Backend ---
build-backend:
Expand Down Expand Up @@ -72,19 +72,19 @@ jobs:
uses: actions/download-artifact@v4
with:
name: angular-build
path: ./frontend/dist/smetovi/ # Download the Angular build
path: ./frontend/dist/smetovi/ # Ensure this is your Angular build folder

- name: Deploy frontend to cPanel via FTP
uses: SamKirkland/[email protected]
with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
local-dir: ./frontend/dist/smetovi/ # Adjust this to match your project build output
server-dir: /public_html/frontend/ # Path where frontend files are deployed on server
local-dir: ./frontend/dist/smetovi/ # Deploy the actual files
server-dir: /public_html/ # Upload to the existing public_html folder
port: ${{ secrets.FTP_PORT }}
log-level: verbose
delete: true # Add this to clean the target directory before deploying
force: true # This will re-upload all files, even unchanged ones

# --- Deploy Backend ---
deploy-backend:
Expand All @@ -99,16 +99,16 @@ jobs:
uses: actions/download-artifact@v4
with:
name: backend-artifact
path: ./backend # Download the backend code
path: ./backend/ # Download the backend files

- name: Deploy backend to cPanel via FTP
uses: SamKirkland/[email protected]
with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
local-dir: ./backend/ # Adjust this to the correct backend build folder
server-dir: /public_html/backend/ # Path where backend files are deployed on server
local-dir: ./backend/ # Path to your backend build
server-dir: /api/ # Deploy directly to /api/ folder
port: ${{ secrets.FTP_PORT }}
log-level: verbose
delete: true # Add this to clean the target directory before deploying
force: true # This will re-upload all files, even unchanged ones
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
Expand Down
7 changes: 6 additions & 1 deletion backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ db.connect((err) => {
console.log('Connected to MySQL database');
});

// Determine if the environment is production or development
const frontendPath = process.env.NODE_ENV === 'production'
? path.join(__dirname, '../../public_html') // For cPanel (production)
: path.join(__dirname, '../frontend/dist/smetovi'); // For local development

// Serve the Angular frontend
app.use(express.static(path.join(__dirname, '../frontend/dist/smetovi')));

Expand All @@ -38,7 +43,7 @@ app.get('/api/data', (req, res) => {

// Handle Angular routes
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../frontend/dist/smetovi/index.html'));
res.sendFile(path.join(frontendPath, 'index.html'));
});

app.listen(PORT, () => {
Expand Down
Loading