I've been trying to deploy my application to Heroku and it has deployed successfully, but I can't seem to get the backend api to work. Instead of using the sites url, it uses localhost:5000 instead.
In heroku , I have set PORT = https://rachael-reddit-clone.herokuapp.com/api
index.js
const PORT = process.env.PORT || 5000;
app.use(express.json());
app.use(cors({credentials:true,origin:'https://rachael-reddit-clone.herokuapp.com'}));
app.get("/",(req,res) => {
res.sendFile(path.join(__dirname,"reddit-clone","build","index.html"))
})
app.get('/api',(req,res) => {
res.send('api section');
})
app.use('/api/user',userRoute);
app.use('/api/community',communityRoute);
app.use('/api/communityMember',communityMemberRoute);
app.use('/api/post',postRoute);
package.json (express )
"engines": {
"node": "12.16.3"
},
"proxy": "https://rachael-reddit-clone.herokuapp.com/api"
question from:
https://stackoverflow.com/questions/65834591/how-to-retrieve-node-backend-api-from-heroku-application 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…