proxy.ts 1.1 KB

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