const express = require("express");
const router = express.Router();
router.get("/movies", (req, res) => {
try {
fetch(
`https://api.themoviedb.org/3/movie/now_playing?api_key=${process.env.MOVIE_API_KEY}&language=en-US&page=1®ion=GB`
)
.then((res) => res.json())
.then((data) => res.status(200).json(data));
} catch (err) {
res.status(500).json(err);
}
});
router.get("/hello", (req, res) => {
res.send("<h1>Hello</h1>");
});
module.exports = router;
Trying to hide my API key using back-end server as a relay. However after deployment when I go to the endpoint ending with /movies, just an empty object {} is returned. When I go to the test endpoint ending with /hello, it is working perfectly. The endpoint /movies is working fine locally but not on deployment. Please help how I can rectify this.