thunderhub/pages/api/v1.tsx
2020-05-13 07:15:10 +02:00

30 lines
668 B
TypeScript

import { ApolloServer } from 'apollo-server-micro';
import { thunderHubSchema } from 'api/schemas';
import { getIp } from 'api/helpers/helpers';
import getConfig from 'next/config';
import Cors from 'micro-cors';
const { publicRuntimeConfig } = getConfig();
const { apiBaseUrl } = publicRuntimeConfig;
const cors = Cors({
origin: true,
});
const apolloServer = new ApolloServer({
schema: thunderHubSchema,
context: async ({ req }: any) => {
const ip = getIp(req);
return { ip };
},
});
const handler = apolloServer.createHandler({ path: apiBaseUrl });
export const config = {
api: {
bodyParser: false,
},
};
export default cors(handler);