Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix missing endpoint for self hosted (#30312)

Joshen Lim3eb5659a94eb
diff --git a/apps/studio/middleware.ts b/apps/studio/middleware.ts
new file mode 100644
index 00000000000..d8715f54c27
--- /dev/null
+++ b/apps/studio/middleware.ts
@@ -0,0 +1,19 @@
+import { IS_PLATFORM } from 'lib/constants'
+import type { NextRequest } from 'next/server'
+
+export const config = {
+ matcher: '/api/:function*',
+}
+
+// [Joshen] Return 404 for all next.js API endpoints EXCEPT the ones we use in hosted:
+const HOSTED_SUPPORTED_API_URLS = ['/ai/sql/suggest', '/ai/sql/generate-v2', '/get-ip-address']
+
+export function middleware(request: NextRequest) {
+ const url = request.url
+ if (IS_PLATFORM && !HOSTED_SUPPORTED_API_URLS.some((url) => request.url.endsWith(url))) {
+ return Response.json(
+ { success: false, message: 'Endpoint not supported on hosted' },
+ { status: 404 }
+ )
+ }
+}
diff --git a/apps/studio/pages/api/projects/[ref]/settings.ts b/apps/studio/pages/api/projects/[ref]/settings.ts
new file mode 100644
index 00000000000..f80694a590a
--- /dev/null
+++ b/apps/studio/pages/api/projects/[ref]/settings.ts
@@ -0,0 +1,58 @@
+import { NextApiRequest, NextApiResponse } from 'next'
+
+import { components } from 'api-types'
+import apiWrapper from 'lib/api/apiWrapper'
+
+export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler)
+
+async function handler(req: NextApiRequest, res: NextApiResponse) {
+ const { method } = req
+
+ switch (method) {
+ case 'GET':
+ return handleGetAll(req, res)
+ default:
+ res.setHeader('Allow', ['GET'])
+ res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } })
+ }
+}
+
+const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {
+ // Platform specific endpoint
+ const response: components['schemas']['ProjectSettingsResponse'] = {
+ app_config: {
+ db_schema: 'public',
+ endpoint: '',
+ },
+ cloud_provider: 'AWS',
+ db_dns_name: '',
+ db_host: 'localhost',
+ dp_ip_addr_config: '',
+ db_name: 'postgres',
+ // @ts-expect-error API is typed wrongly
+ db_port: 5432,
+ db_user: 'postgres',
+ inserted_at: '2021-08-02T06:40:40.646Z',
+ jwt_secret:
+ process.env.AUTH_JWT_SECRET ?? 'super-secret-jwt-token-with-at-least-32-characters-long',
+ name: process.env.DEFAULT_PROJECT_NAME || 'Default Project',
+ ref: 'default',
+ region: 'ap-southeast-1',
+ service_api_keys: [
+ {
+ api_key: process.env.SUPABASE_SERVICE_KEY ?? '',
+ name: 'service_role key',
+ tags: 'service_role',
+ },
+ {
+ api_key: process.env.SUPABASE_ANON_KEY ?? '',
+ name: 'anon key',
+ tags: 'anon',
+ },
+ ],
+ ssl_enforced: false,
+ status: 'ACTIVE_HEALTHY',
+ }
+
+ return res.status(200).json(response)
+}
diff --git a/apps/studio/pages/api/props/project/[ref]/settings.ts b/apps/studio/pages/api/props/project/[ref]/settings.ts
deleted file mode 100644
index 418b8f79a9c..00000000000
--- a/apps/studio/pages/api/props/project/[ref]/settings.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-import { NextApiRequest, NextApiResponse } from 'next'
-
-import apiWrapper from 'lib/api/apiWrapper'
-import { DEFAULT_PROJECT, PROJECT_ENDPOINT } from 'pages/api/constants'
-
-export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler)
-
-async function handler(req: NextApiRequest, res: NextApiResponse) {
- const { method } = req
-
- switch (method) {
- case 'GET':
- return handleGetAll(req, res)
- default:
- res.setHeader('Allow', ['GET'])
- res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } })
- }
-}
-
-const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {
- // Platform specific endpoint
- const response = {
- project: {
- ...DEFAULT_PROJECT,
- cloud_provider: 'AWS',
- region: 'ap-southeast-1',
- db_dns_name: '-',
- db_host: 'localhost',
- db_name: 'postgres',
- db_port: 5432,
- db_ssl: false,
- db_user: 'postgres',
- jwt_secret:
- process.env.AUTH_JWT_SECRET ?? 'super-secret-jwt-token-with-at-least-32-characters-long',
- },
- services: [
- {
- id: 1,
- name: 'Default API',
- service_api_keys: [
- {
- api_key: process.env.SUPABASE_SERVICE_KEY,
- api_key_encrypted: '-',
- name: 'service_role key',
- tags: 'service_role',
- },
- {
- api_key: process.env.SUPABASE_ANON_KEY,
- api_key_encrypted: '-',
- name: 'anon key',
- tags: 'anon',
- },
- ],
- app: { id: 1, name: 'Auto API' },
- app_config: {
- db_schema: 'public',
- endpoint: PROJECT_ENDPOINT,
- realtime_enabled: true,
- },
- },
- ],
- }
-
- return res.status(200).json(response)
-}