graphql - 在 nextjs 生产中无法访问 Graphql 服务器
问题描述
我在本地对其进行了测试,它可以完美地从 graphql 获取数据。但是,直到生产版本,游乐场显示消息服务器无法访问。我的本地服务器和生产服务器有什么不同?
- 我在 digitalOcean 中手动设置服务器。它在 nginx 和 pm2 中启动 web。
- 我已经在我的服务器上安装了 mongdb。
- 这个项目是从 nextjs 框架创建的
下面是我的 ApolloServer 代码:
import { ApolloServer } from "apollo-server-micro";
import { MongoClient } from "mongodb";
import { schema } from "@/apollo/schema";
let db;
const apolloServer = new ApolloServer({
schema,
playground: true,
context: async ({ res, req }) => {
if (!db) {
try {
const dbClient = new MongoClient(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
if (!dbClient.isConnected()) await dbClient.connect();
db = dbClient.db("databaseName");
} catch (error) {
console.log(`error while connecting with graphql context (db):`;
}
}
return { db, res, req };
},
});
export const config = {
api: {
bodyParser: false,
},
};
export default apolloServer.createHandler({ path: "/api/graphql" });
更新:已解决 uri 错误吗?那是我的网站网址。
return new ApolloClient({
ssrMode,
link: new HttpLink({
uri: `http://dayfruit.staging.domian.com/api/graphql`,
credentials: "include",
fetch,
}),
cache,
});
解决方案
推荐阅读
- java - 用文本替换内容控件
- mysql - 如何在laravel中检测内部服务器错误(500)
- ruby-on-rails - 在同一线程中使用辅助/自治事务
- java - 在哪里为 java 中的 SSLException 添加证书?
- python-3.x - Pip 无法正常工作,我似乎无法找到解决方法
- square - SquarePOS - 为什么仪表板上没有出现销售?
- validation - ckeditor | 内的“必需”属性
- c# - 是否可以在 C# wpf(网格)中绘制形状,如果网格按行和单元格拆分,并且每行内部包含一个堆栈面板?
- excel - Excel 数据透视表 VBA:如何将总和放入行标签中
- laravel - 在 laravel 中,数据未插入数据库