Setting up an Express app was a breeze for me, but when it comes to deploying it on Azure Web App, I'm hitting some roadblocks!
The structure of my app is quite simple: a static web app with its own API. Requests to /website.com/api are forwarded to a different server to avoid CORS issues, while everything else is served from the static site area.
Below is the code snippet for my entire Express App:
import express from 'express'
import fetch from 'node-fetch'
const app = express()
const API_SERVER_URL = 'https://my-web-site.com/'
app.listen(3000, () => console.log('Express listening at port 3000'))
app.use(express.static('public'))
app.use(express.json({ limit: '1mb' })
// Code for handling POST and GET requests to '/api'
While everything runs smoothly on localhost, after deploying to Azure Web App, I encounter a strange issue. The static pages load fine, but any request to my-web-site.com/api/ results in a 404 error.
I suspect that Azure's server is looking for an /api/ folder or index.html within it, causing the 404 instead of processing the request through my root index.js file.
Although I've come across some outdated instructions on redirecting in Azure, they don't seem to apply here. I'm yet to find a solution either in the console settings/configurations or networking options.
I've attempted creating a web.config file for redirection purposes, but it seems like I might be missing a step. Before sharing the code, I'd appreciate some guidance to ensure I'm on the right track. It feels like I'm overlooking something obvious.