proxy.ts47 lines · main
| 1 | import type { NextRequest } from 'next/server' |
| 2 | |
| 3 | import { IS_PLATFORM } from '@/lib/constants' |
| 4 | |
| 5 | export const config = { |
| 6 | matcher: '/api/:function*', |
| 7 | } |
| 8 | |
| 9 | // [Joshen] Return 404 for all next.js API endpoints EXCEPT the ones we use in hosted: |
| 10 | const HOSTED_SUPPORTED_API_URLS = [ |
| 11 | '/ai/sql/generate-v4', |
| 12 | '/ai/sql/policy', |
| 13 | '/ai/feedback/rate', |
| 14 | '/ai/code/complete', |
| 15 | '/ai/sql/cron-v2', |
| 16 | '/ai/sql/title-v2', |
| 17 | '/ai/sql/filter-v1', |
| 18 | '/ai/onboarding/design', |
| 19 | '/ai/feedback/classify', |
| 20 | '/ai/docs', |
| 21 | '/ai/sql/parse-client-code', |
| 22 | '/get-ip-address', |
| 23 | '/get-utc-time', |
| 24 | '/get-deployment-commit', |
| 25 | '/check-cname', |
| 26 | '/edge-functions/test', |
| 27 | '/edge-functions/body', |
| 28 | '/generate-attachment-url', |
| 29 | '/incident-status', |
| 30 | '/incident-banner', |
| 31 | '/status-override', |
| 32 | '/api/integrations/stripe-sync', |
| 33 | '/content/graphql', |
| 34 | '/parse-query', |
| 35 | ] |
| 36 | |
| 37 | export function proxy(request: NextRequest) { |
| 38 | if ( |
| 39 | IS_PLATFORM && |
| 40 | !HOSTED_SUPPORTED_API_URLS.some((url) => request.nextUrl.pathname.endsWith(url)) |
| 41 | ) { |
| 42 | return Response.json( |
| 43 | { success: false, message: 'Endpoint not supported on hosted' }, |
| 44 | { status: 404 } |
| 45 | ) |
| 46 | } |
| 47 | } |