【发布时间】:2021-06-10 21:39:24
【问题描述】:
我有一个 apollo graphql 服务器,我想为该 Stripe 或一些微服务添加一个自定义端点,如何添加其他端点?
我不想创建其他项目。
const app = express();
var corsOptions = {
origin:["https://localhost:3000"],
credentials: true
};
// RESOLVERS
const resolvers = require("./graphql/resolvers/index");
const resolveFunctions = {
JSON: GraphQLJSON,
Upload: GraphQLUpload
};
// models
const Admin = require("./models/Admin");
const pubsub = new PubSub();
// SCHEMA
const server = new ApolloServer({
typeDefs: importSchema("./graphql/schema.graphql"),
resolvers,
resolveFunctions,
context: ({ req }) => ({
Admin,
activeAdmin: req ? req.activeAdmin : null
})
});
app.use(async (req, res, next) => {
const token = req.headers["authorization"];
if (token && token !== "null") {
try {
const activeAdmin = await jwt.verify(token, process.env.SECRET_KEY);
req.activeAdmin = activeAdmin;
} catch (e) {
console.log("ERROR", e);
}
}
next();
});
server.applyMiddleware({ app, cors: corsOptions });
const httpServer = http.createServer(app);
server.installSubscriptionHandlers(httpServer);
httpServer.listen(process.env.PORT || 4004, () =>
console.log(
`???? Server ready at http://localhost:4004${server.graphqlPath}`
)
);
那么如何为 webhook 添加多个端点? 谢谢
【问题讨论】:
标签: node.js graphql apollo-server