Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

express - How to retrieve node backend api from heroku application

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...