首页 > 解决方案 > Next-absolute-url 在 Nextjs 的生产环境中不起作用

问题描述

我在 Nextjs 中使用 absoluteUrl 来获取来源。在 localhost 我得到的来源是http://localhost:3000这很好。

但是当我将此来源导入到社交共享按钮时,我得到的来源是 生产页面中的http://localhost:3000

谁能告诉我如何为生产编写代码?

 const fetchRelative = (req: any) => {
     const { origin } = absoluteUrl(req);
     return origin;
 }
 const origin = await fetchRelative(reqObj);

我在我的页面中使用了此代码。

标签: javascriptnext.jsabsolute-path

解决方案


推荐阅读