I try to get data e from 3 differents location in my site.
- /
- /profile
- /friends/profile
Express :
router.get("/image/:id", async (req, res) => {
const recipe = await Recipe.findById(req.params.id);
res.set("Content-Type", "image/png");
res.send(recipe.image);
});
and in FE:
<img src={process.env.NODE_ENV === "production" ? "/image/123" : `http://localhost:5000/image/123` alt="example"/>
its work on homepage due to img url is added to homepage /image/:id.
but on option 2 and 3 it doesnt upload image /profile/image/:id.
CodePudding user response:
create env variable like IMAGE_BASE_URL and use it in production
<img src={process.env.NODE_ENV === "production" ? process.env.IMAGE_BASE_URL "/image/123" : `http://localhost:5000/image/123` alt="example"/>