我的项目涉及不止一个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
)。
有什么建议吗?