Skip to content

Instantly share code, notes, and snippets.

@orozcorp
Created December 20, 2022 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orozcorp/f5760da6794119b3e7832ae62f179810 to your computer and use it in GitHub Desktop.
Save orozcorp/f5760da6794119b3e7832ae62f179810 to your computer and use it in GitHub Desktop.
Apollo Server with micro-cors and apollo-server-micro
import Cors from "micro-cors";
import ApolloServer from "../../apollo/config/server";
const cors = Cors();
export const config = {
api: {
bodyParser: false,
},
};
const serverStarted = ApolloServer.start();
export default cors(async (req, res) => {
if (req.method === "OPTIONS") {
res.end();
return false;
}
await serverStarted;
await ApolloServer.createHandler({
path: "/api",
})(req, res);
});
import { ApolloServer } from "apollo-server-micro";
import schema from "./schema";
import resolvers from "./resolvers";
import { context } from "./context";
import { ApolloServerPluginLandingPageDisabled } from "apollo-server-core";
const typeDefs = schema;
export default new ApolloServer({
typeDefs,
resolvers,
context,
csrfPrevention: true,
cache: "bounded",
plugins: [ApolloServerPluginLandingPageDisabled()],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment