-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathroute.ts
53 lines (44 loc) · 1.72 KB
/
route.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { keystoneContext } from 'keystone/context'
import { getSessionContext } from 'keystone/context'
import { createYoga } from 'graphql-yoga'
import { createFetch } from '@whatwg-node/fetch'
import { NextRequest, NextResponse } from 'next/server'
import { auth } from 'lib/auth'
const { handleRequest } = createYoga({
schema: keystoneContext.graphql.schema,
context: async () => getSessionContext(),
graphqlEndpoint: '/api/graphql',
fetchAPI: {
...createFetch({
formDataLimits: {
// Maximum allowed file size (in bytes)
fileSize: 4500,
// Maximum allowed number of files
files: 10,
// Maximum allowed size of content (operations, variables etc...)
fieldSize: 1000000,
// Maximum allowed header size for form data
headerSize: 1000000,
},
}),
Response,
},
})
export const GET = auth(function GET(req) {
if (!req.auth?.allowAdminUI)
return NextResponse.json({ message: 'Not authenticated' }, { status: 401 })
const ctx = { waitUntil: () => new Promise(() => {}) }
return handleRequest(req, ctx)
}) as (req: NextRequest) => Promise<NextResponse>
export const POST = auth(function POST(req) {
if (!req.auth?.allowAdminUI)
return NextResponse.json({ message: 'Not authenticated' }, { status: 401 })
const ctx = { waitUntil: () => new Promise(() => {}) }
return handleRequest(req, ctx)
}) as (req: NextRequest) => Promise<NextResponse>
export const OPTIONS = auth(function OPTIONS(req) {
if (!req.auth?.allowAdminUI)
return NextResponse.json({ message: 'Not authenticated' }, { status: 401 })
const ctx = { waitUntil: () => new Promise(() => {}) }
return handleRequest(req, ctx)
}) as (req: NextRequest) => Promise<NextResponse>