无法从Heroku上部署的Strapi应用程序中使用React Local主机获取数据
我现在已经在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论