我多次尝试部署 MERN 项目,但一直遇到问题。首先,它会在本地运行,而不是在服务器上运行。现在,我已尝试使用 Azure Web 应用程序服务进行设置 - 它表示我的应用程序已部署并正在等待我的内容。但是,当我在本地运行它时,提交时没有任何反应,并且不显示现有的数据库条目。如有任何帮助,我们将不胜感激。
这里是存储库的链接 - https://github.com/zachmvm/IronWatchSecurity
我尝试编辑 yml 文件,这似乎修复了将应用程序上传到 Azure 时出现的错误。但当我尝试访问 Azure Web 应用程序上的 URL 时,它仍然不显示。
这对我有用。
yml
:
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy Node.js app to Azure Web App - mernnodeapp
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js version
uses: actions/setup-node@v3
with:
node-version: '20.x'
# Build frontend
- name: Build frontend
run: |
npm install
npm run build
working-directory: frontend/
# Build backend
- name: Build backend
run: |
npm install
npm run build
working-directory: backend/
# Zip artifacts for deployment
- name: Zip artifacts for deployment
run: |
zip -r frontend.zip frontend/*
zip -r backend.zip backend/*
# Upload artifacts for deployment job
- name: Upload artifacts for deployment job
uses: actions/upload-artifact@v3
with:
name: frontend-app
path: frontend.zip
- uses: actions/upload-artifact@v3
with:
name: backend-app
path: backend.zip
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download frontend artifact from build job
uses: actions/download-artifact@v3
with:
name: frontend-app
- name: Unzip frontend artifact for deployment
run: unzip frontend.zip
- name: Download backend artifact from build job
uses: actions/download-artifact@v3
with:
name: backend-app
- name: Unzip backend artifact for deployment
run: unzip backend.zip
- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'mernnodeapp'
slot-name: 'Production'
package: .
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_xxxxxxxxxxxxxxxxx }}
要使用发布配置文件从 GitHub 进行部署,您需要启用
SCM Basic Auth Publishing Credentials
npm run start
。pm2 serve home/site/wwwroot/frontend/build --no daemon --spa
注意:确保文件的路径或目录正确
OUTPUT
: