MCPcopy
hub / github.com/prisma/prisma / createStudioRequestHandler

Function createStudioRequestHandler

packages/cli/src/Studio.ts:465–541  ·  view source on GitHub ↗
({
  adapter,
  executor,
  ppgDbInfo,
  protocol,
  version,
}: {
  adapter: StudioAdapterType
  executor: Executor
  ppgDbInfo: Awaited<ReturnType<typeof getPpgInfo>>
  protocol: string
  version: string
})

Source from the content-addressed store, hash-verified

463}
464
465function createStudioRequestHandler({
466 adapter,
467 executor,
468 ppgDbInfo,
469 protocol,
470 version,
471}: {
472 adapter: StudioAdapterType
473 executor: Executor
474 ppgDbInfo: Awaited<ReturnType<typeof getPpgInfo>>
475 protocol: string
476 version: string
477}): (request: Request) => Promise<Response> {
478 let projectHash: string | null = null
479
480 return async (request) => {
481 const { pathname } = new URL(request.url)
482
483 if (request.method === 'OPTIONS') {
484 return optionsResponse()
485 }
486
487 if (isGetOrHeadRequest(request.method) && pathname === '/') {
488 const contentType = FILE_EXTENSION_TO_CONTENT_TYPE[extname('index.html')]
489
490 return textResponse(getIndexHtml(adapter), 200, { 'Content-Type': contentType })
491 }
492
493 if (isGetOrHeadRequest(request.method) && pathname === '/favicon.ico') {
494 return textResponse(PRISMA_LOGO_SVG, 200, { 'Content-Type': 'image/svg+xml' })
495 }
496
497 if (
498 isGetOrHeadRequest(request.method) &&
499 (pathname === `/${STUDIO_JS_FILE_NAME}` || pathname === `/${STUDIO_CSS_FILE_NAME}`)
500 ) {
501 return serveStudioAsset(pathname)
502 }
503
504 if (request.method === 'POST' && pathname === '/bff') {
505 return handleStudioBffRequest(await request.json(), executor)
506 }
507
508 if (request.method === 'POST' && pathname === '/telemetry') {
509 const { eventId, name, payload, timestamp } = (await request.json()) as Parameters<
510 NonNullable<StudioProps['onEvent']>
511 >[0]
512
513 if (name !== 'studio_launched') {
514 return emptyResponse(200)
515 }
516
517 const input: Check.Input = {
518 check_if_update_available: false,
519 client_event_id: eventId,
520 command: name,
521 information: JSON.stringify({
522 eventPayload: payload,

Callers 1

parseMethod · 0.85

Calls 8

optionsResponseFunction · 0.85
isGetOrHeadRequestFunction · 0.85
textResponseFunction · 0.85
getIndexHtmlFunction · 0.85
serveStudioAssetFunction · 0.85
handleStudioBffRequestFunction · 0.85
emptyResponseFunction · 0.85
catchMethod · 0.80

Tested by

no test coverage detected