66 lines
1.9 KiB
YAML
66 lines
1.9 KiB
YAML
name: Deploy React App to Azure Web App
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- int # oder dein Branch
|
|
workflow_dispatch: # Ermöglicht manuelles Triggern
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: '18'
|
|
cache: 'npm' # Aktiviert Caching für schnellere Builds
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
npm ci
|
|
npm install express
|
|
|
|
- name: Build React app
|
|
run: npm run build
|
|
|
|
- name: Create server.js for Azure
|
|
run: |
|
|
# Create ES module compatible server.js directly in root
|
|
cat > server.js << 'EOF'
|
|
import express from 'express';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
const app = express();
|
|
|
|
app.use(express.static(path.join(__dirname, 'dist')));
|
|
|
|
app.get('/*', function(req, res) {
|
|
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
|
|
});
|
|
|
|
const port = process.env.PORT || 8080;
|
|
app.listen(port, '0.0.0.0', () => {
|
|
console.log(`Server running on port ${port}`);
|
|
console.log(`Serving from: ${__dirname}/dist`);
|
|
});
|
|
EOF
|
|
|
|
# Verify the file was created
|
|
echo "=== server.js content ==="
|
|
cat server.js
|
|
|
|
- name: 'Deploy to Azure Web App'
|
|
uses: azure/webapps-deploy@v3
|
|
with:
|
|
app-name: 'poweron-nyla'
|
|
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_D6C9359A57C5448A8C0BFA2D4C4B2068 }}
|
|
clean: true
|