向原点发送请求时出错。 Apollo Engine如何配置Apollo Engine的来源?

时间:2018-06-20 20:06:15

标签: javascript node.js cors apollo apollo-server

我正在尝试向/graphiql IDE发出请求,并且收到有关我的来源的超时错误。

  

ERRO [0515]向源发送请求时出错。这意味着原始GraphQL服务器没有及时响应代理请求。若要解决此问题,请验证引擎配置中的Origin规范与相应的GraphQL服务器匹配。如果错误是超时错误,请考虑在引擎配置中增加origin.requestTimeout。错误=“发布http://127.0.0.1:51301/graphql:net / http:请求已取消(在等待标题时超出了Client.Timeout)” url =“ http://127.0.0.1:51301/graphql”

请记住,每次运行时url(http://127.0.0.1:51301/graphql)端口都会更改,因此这使我相信它必须是apollo引擎代理正在运行的url,因为服务器上的任何内容都不会更改端口号,例如那。

我的阿波罗引擎配置就是这样

import { ApolloEngine } from "apollo-engine";
import { ENGINE_API_KEY, PORT } from "../config/keys";
import { INFO } from "./utils/logging";

import app from './app';

const LOG_START = () => INFO(`Listening! at port: ${PORT}`);

/*
  setup Apollo Engine
*/
const engine = new ApolloEngine({
  apiKey: process.env.ENGINE_API_KEY || ENGINE_API_KEY,
});

/*
  Config for Apollo Engine to serve
*/
const ENGINE_SERVE = {
  port: PORT,
  graphqlPaths: ["/graphql"],
  expressApp: app,
  launcherOptions: {
    startupTimeout: 3000
  }
};

/*
  Entry point for application starts server
*/
engine.listen(ENGINE_SERVE, LOG_START);

我的端口号是:8080

我的Apollo服务器是这样设置的

import cors from "cors";
import morgan from "morgan";
import express from "express";
import bodyParser from "body-parser";
import compression from "compression";
import { graphqlExpress, graphiqlExpress } from "apollo-server-express";

import connectDb from "./connectors/mongo-connector";
import schema from "./schemas/schema";

/*
  Create express application
*/
const app = express();

/*
  Configure graphql server
*/
const GRAPH_EXPRESS = graphqlExpress({
  schema,
  tracing: true,
  context: { db: async () => await connectDb() }
});

/*
  Configure Graphql IDE for testing
*/
const GRAPH_IDE = graphiqlExpress({ endpointURL: "/graphql" });

/*
  Middleware and route handlers
*/
app.use(cors());
app.use(morgan("dev"));
app.use(compression());
app.use("/graphql", bodyParser.json(), GRAPH_EXPRESS);
app.use("/graphiql", GRAPH_IDE);

export default app;

我不明白为什么我尝试过的请求没有被退回

增加我的起点超时,并在引擎配置中显式设置我的起点。但是由于端口每次更改,我无法设置错误消息指出的URL,所以我有点不知所措,我们将不胜感激。

"origins": [
    {
      "http": {
        "requestTimeout": "60s",
        "url": "http://localhost:8080/graphql",
        "overrideRequestHeaders": {
          "Host": "localhost"
        }
      }
    }
  ]

1 个答案:

答案 0 :(得分:0)

问题是我的mongo连接器没有通过没有mongo连接而触发,我的端点未超时,并且我误解了错误的含义。

 const GRAPH_EXPRESS = graphqlExpress({
      schema,
      tracing: true,
      context: { db: connectDb() }
 });