如何配置我的 Nuxt 前端应用程序以了解使用 Strapi 的后端的 baseUrl?

How do I configure my Nuxt frontend application to know the baseUrl of the backend which uses Strapi?

我一直在关注这两个教程:

reading through Strapi's documentation 和搜索网络之后,我不知道如何在前端设置我的应用程序的 baseUrl,这样无论我在什么环境中,都会 return 正确的 URL查询后台,例如:

如果我在暂存中,那么这个 baseUrl 将设置为 https://staging.awesomesauce.com,依此类推。

例如,在这些教程中,当他们引用图像时,您会看到他们这样做 <img src="http://localhost:1337/img.jpg />,但是在生产环境中,这将如何工作?

Strapi 的文档有一些关于使用 server.json:

As an example using this configuration with Nginx your server would respond to https://example.com:8443 instead of http://localhost:1337

我看到有一个 config/environments/ 目录,其中包含 developmentproductionstaging,我不知道如何从这些目录中访问某些内容,例如 strapi.currentEnvironment.baseUrl 从我的前端应用程序中的 <img /> 标记或其他地方。我的申请结构如下:

Application
├── frontend
├── backend

我使用 Apollo 从前端到后端进行查询。

是否存在某种魔法代理,其中对 localhost:1337 的引用被重定向到它们各自的环境 URL?

只需在您的 Nuxt 应用程序中使用 ENV variables 并保持不同 .env 文件中的值与您的 Strapi 服务器设置同步....