Skip to content

Commit

Permalink
feat: update web app to work with frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
gitfrosh committed Nov 25, 2023
1 parent 79fed07 commit e573048
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
34 changes: 28 additions & 6 deletions .github/workflows/main_lotr-backend.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# 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 - lotr-backend

on:
Expand All @@ -16,12 +13,37 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Node.js version
# Frontend build steps
- name: Set up Node.js version for frontend
uses: actions/setup-node@v3
with:
node-version: '18.x'
working-directory: ./frontend

- name: npm install for frontend
run: npm install
working-directory: ./frontend

- name: npm run test for frontend
run: npm run test --if-present
working-directory: ./frontend

- name: npm run build for frontend
run: npm run build
working-directory: ./frontend

# Copy build directory to backend
- name: Copy frontend build to backend
run: cp -R ./frontend/build/* ./backend/__BUILD/

# Backend build steps
- name: Set up Node.js version for backend
uses: actions/setup-node@v3
with:
node-version: '18.x'
working-directory: ./backend

- name: npm install, build, and test
- name: npm install, build, and test for backend
run: |
npm install
npm run test --if-present
Expand Down Expand Up @@ -60,4 +82,4 @@ jobs:
app-name: 'lotr-backend'
slot-name: 'Production'
package: .
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_755D03D3D66E4CFEA1B7360C17082E2D }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_755D03D3D66E4CFEA1B7360C17082E2D }}
7 changes: 7 additions & 0 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cors());

app.use(express.static(path.join(__dirname, "/__BUILD"))); // React build

const apiRoutes = require("./routes/api");
const authRoutes = require("./routes/auth");

Expand Down Expand Up @@ -98,6 +100,11 @@ app.use("/v2/", apiLimiter);
app.use("/v2", apiRoutes);
app.use("/auth", authRoutes);

// Handles React frontend requests
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname + "/__BUILD/index.html"));
});

async function start() {
await db.connectDb();
app.listen(server_port, () =>
Expand Down

0 comments on commit e573048

Please sign in to comment.