NGINX和NodeJS + ApolloServer 2.0的路由问题

时间:2019-02-20 11:51:25

标签: node.js express apollo-server

我的项目涉及不止一个Node应用程序,它们监听从不同子目录运行的不同端口:

/
|
|
+-----default (app for schandillia.com)
|
|
+-----graph
        |
        |
        +-----blog (app for graph.schandillia.com/blog)
        |
        |
        +-----abc (app for graph.schandillia.com/abc)

当前,我在其根文件夹中的每个应用都有一个server.js(例如,对于应用 graph.schandillia.com/blog ),/graph/blog/server.js

>

/graph/blog/server.js文件为GraphQL运行 Apollo Server 2.0 ,并使用Express作为中间件。这是此中间件中的路由定义:

// GraphQL: Schema
const server = new ApolloServer({
  typeDefs,
  resolvers,
  playground: {
    endpoint: `/blog`, /* populates the playground endpoint box below the tab-strip. */
    settings: require('./playground.json')
  }
});

// Express: Initialize
const app = express();
// Middleware: GraphQL route
server.applyMiddleware({
  app,
  path: '/'
});

如您所见,此处的path字段设置为/(可通过https://graph.schandillia.com/blog访问)。但是,我希望它指向一个/test子段:https://graph.schandillia.com/blog/test。但是将path设置为/test会返回错误(Cannot GET /blog/test)。

有什么建议吗?

0 个答案:

没有答案