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

Categories

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"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...