I set up a Cloudflare tunnel on my Linux machine to serve a web application. The tunnel has two public hostnames configured:
- Domain: mysite.com, Service: HTTP://localhost:3000
- Domain: mysite.com, Path: api/*, Service: HTTP://localhost:8080
I used cloudflared tunnel route dns to configure the DNS settings.
My frontend makes API calls using axios:
export const fetchUserData = async () => {
return await axios.post(`https://mysite.com/api/fetch-user-data`);
}
The Express server is set up like this:
const server = express();
const SERVER_PORT = 8080;
const corsConfig = {
origin: [
`http://localhost:3000`,
`http://localhost:8080`,
"https://mysite.com",
],
optionsSuccessStatus: 200,
};
server.post("/api/fetch-user-data", Handler.fetchUserData);
server.listen(SERVER_PORT, () => {
console.log(`Server running on port ${SERVER_PORT}`);
});
The frontend loads fine from the public internet, but API requests fail with:
POST https://mysite.com/api/fetch-user-data 404 (Not Found)
Testing curl -X POST http://localhost:8080/api/fetch-user-data locally works perfectly and returns the expected data. However, curl -X POST https://mysite.com/api/fetch-user-data returns nothing.
I tried adding a config.yml file in the .cloudflared directory but it did not help. What am I missing in my tunnel configuration?