mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-23 22:46:35 +01:00
30 lines
668 B
TypeScript
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);
|