无法从Heroku上部署的Strapi应用程序中使用React Local主机获取数据

发布于 2025-02-13 13:58:39 字数 1583 浏览 0 评论 0原文

我现在已经在Heroku上部署了我的Strapi应用程序,并使用了Postgres插件。

我将所有Postgres信息添加到所需的文件中,但仍然无法从Strapi获取数据。 我不确定是否有Local -Host/1337或我的Strapi应用程序URL以及在哪里拥有它。尝试获取时会出现错误

--- frontend ---
// App.js
// apollo client
const client = new ApolloClient({
  uri: 'http://localhost:1337/graphql',
  cache: new InMemoryCache()
})

--- - ------ config => server.js

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  app: {
    keys: env.array('APP_KEYS'),
  },
});

config => database.js

const path = require('path');
module.exports = ({ env }) => ({
  connection: {
    client: 'sqlite',
    connection: {
      filename: path.join(__dirname, '..', env('DATABASE_FILENAME', '.tmp/data.db')),
    },
    useNullAsDefault: true,
  },
});

config => env =>生产 - > server.js

module.exports = ({ env }) => ({
  proxy: true,
  url: env('MY_HEROKU_URL'),
  app: { 
    keys: env.array('APP_KEYS')
  },
}) 

config => env =>生产=>数据库

const parse = require('pg-connection-string').parse;
const config = parse(process.env.DATABASE_URL);
console.log(config)

module.exports = ({ env }) => ({
  connection: {
    client: 'postgres',
    connection: {
      host: config.host,
      port: config.port,
      database: config.database,
      user: config.user,
      password: config.password,
      ssl: {
        rejectUnauthorized: false
      },
    },
    debug: false,
  },
});

I have deployed my strapi app on Heroku now and have used the postgres addon.

I added all postgres info into the required files, but still cannot fetch data from strapi.
I am not sure to have localhost/1337 or my strapi app url and where to have it. I get an error when trying to fetch

--- frontend ---
// App.js
// apollo client
const client = new ApolloClient({
  uri: 'http://localhost:1337/graphql',
  cache: new InMemoryCache()
})

--- backend ---
config => server.js

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  app: {
    keys: env.array('APP_KEYS'),
  },
});

config => database.js

const path = require('path');
module.exports = ({ env }) => ({
  connection: {
    client: 'sqlite',
    connection: {
      filename: path.join(__dirname, '..', env('DATABASE_FILENAME', '.tmp/data.db')),
    },
    useNullAsDefault: true,
  },
});

config => env => production -> server.js

module.exports = ({ env }) => ({
  proxy: true,
  url: env('MY_HEROKU_URL'),
  app: { 
    keys: env.array('APP_KEYS')
  },
}) 

config => env => production => database.js

const parse = require('pg-connection-string').parse;
const config = parse(process.env.DATABASE_URL);
console.log(config)

module.exports = ({ env }) => ({
  connection: {
    client: 'postgres',
    connection: {
      host: config.host,
      port: config.port,
      database: config.database,
      user: config.user,
      password: config.password,
      ssl: {
        rejectUnauthorized: false
      },
    },
    debug: false,
  },
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文