thunderhub/pages/api/v1.tsx

31 lines
676 B
TypeScript
Raw Normal View History

import { ApolloServer } from 'apollo-server-micro';
2020-05-12 06:19:12 +02:00
import { thunderHubSchema } from 'src/api/schemas';
import { getIp } from 'src/api/helpers/helpers';
2020-04-14 23:02:33 +02:00
import getConfig from 'next/config';
import Cors from 'micro-cors';
2020-04-14 23:02:33 +02:00
const { publicRuntimeConfig } = getConfig();
const { apiBaseUrl } = publicRuntimeConfig;
2020-04-14 23:02:33 +02:00
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);