Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Proxy backend calls for better DX [WIP]

Tomas Valenta2244d29c56ec
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
new file mode 100644
index 000000000..81b33b40c
--- /dev/null
+++ b/.devcontainer/devcontainer.json
@@ -0,0 +1,6 @@
+{
+ "image": "mcr.microsoft.com/devcontainers/universal:2",
+ "features": {
+ "ghcr.io/devcontainers-contrib/features/poetry:2": {}
+ }
+}
\ No newline at end of file
diff --git a/components/Editor/Sidebar/index.tsx b/components/Editor/Sidebar/index.tsx
index 7ed61c76a..e5af598ab 100644
--- a/components/Editor/Sidebar/index.tsx
+++ b/components/Editor/Sidebar/index.tsx
@@ -81,7 +81,7 @@ function Sidebar({
const {
trigger: generate,
isMutating: isDeployRequestRunning,
- } = useSWRMutation(`${apiHost}/generate`, handlePostGenerate)
+ } = useSWRMutation('/api/generate', handlePostGenerate)
const [selectors] = useStateStore()
const envs = selectors.use.envs()
diff --git a/docker-compose.yml b/docker-compose.yml
index 71cc28038..690d4410b 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -10,8 +10,8 @@ services:
- NEXT_PUBLIC_SUPABASE_URL=http://supabase_kong_workspace:8000
- SUPABASE_SERVICE_ROLE_KEY=${SUPABASE_SERVICE_ROLE_KEY}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- ports:
- - 49155:49155
+ expose:
+ - 49155
external_links:
- supabase_kong_workspace
- supabase_db_workspace
@@ -30,8 +30,8 @@ services:
- NODE_ENV=development
- SUPABASE_URL=http://supabase_kong_workspace:8000
+ - API_URL=http://supabase_db_workspace:49155
- SUPABASE_POSTGRES_URL=postgresql://postgres:postgres@supabase_db_workspace:5432/postgres
- - NEXT_PUBLIC_SUPABASE_URL=${NEXT_PUBLIC_SUPABASE_URL}
- SUPABASE_SERVICE_ROLE_KEY=${SUPABASE_SERVICE_ROLE_KEY}
- NEXT_PUBLIC_SUPABASE_ANON_KEY=${NEXT_PUBLIC_SUPABASE_ANON_KEY}
ports:
diff --git a/next.config.js b/next.config.js
index 2398a09ab..9239c3cb1 100644
--- a/next.config.js
+++ b/next.config.js
@@ -2,7 +2,19 @@
const nextConfig = {
swcMinify: true,
experimental: {
- swcPlugins: [['next-superjson-plugin', {}]],
+ // swcPlugins: [['next-superjson-plugin', {}]],
+ },
+ async rewrites() {
+ return [
+ {
+ source: '/generate',
+ destination: 'http://localhost:49155/generate',
+ },
+ {
+ source: '/db',
+ destination: 'http://localhost:3000/db',
+ },
+ ]
},
}
diff --git a/package-lock.json b/package-lock.json
index 839e2788e..f9da53461 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -26,6 +26,7 @@
"@tiptap/starter-kit": "^2.0.0-beta.220",
"clsx": "^1.2.1",
"fuse.js": "^6.6.2",
+ "http-proxy": "^1.18.1",
"human-id": "^4.0.0",
"immer": "^9.0.19",
"lucide-react": "^0.130.1",
@@ -48,6 +49,7 @@
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.9",
+ "@types/http-proxy": "^1.17.10",
"@types/node": "^18.14.6",
"@types/randomcolor": "^0.5.7",
"@types/react": "^18.0.28",
@@ -1020,6 +1022,15 @@
"@types/unist": "*"
}
},
+ "node_modules/@types/http-proxy": {
+ "version": "1.17.10",
+ "resolved": "https://registry.npmjs.org/@types/http-proxy/-/http-proxy-1.17.10.tgz",
+ "integrity": "sha512-Qs5aULi+zV1bwKAg5z1PWnDXWmsn+LxIvUGv6E2+OOMYhclZMO+OXd9pYVf2gLykf2I7IV2u7oTHwChPNsvJ7g==",
+ "dev": true,
+ "dependencies": {
+ "@types/node": "*"
+ }
+ },
"node_modules/@types/json5": {
"version": "0.0.29",
"resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz",
@@ -3040,6 +3051,11 @@
"node": ">=0.10.0"
}
},
+ "node_modules/eventemitter3": {
+ "version": "4.0.7",
+ "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
+ "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
+ },
"node_modules/ext": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz",
@@ -3194,6 +3210,25 @@
"integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==",
"dev": true
},
+ "node_modules/follow-redirects": {
+ "version": "1.15.2",
+ "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
+ "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://github.com/sponsors/RubenVerborgh"
+ }
+ ],
+ "engines": {
+ "node": ">=4.0"
+ },
+ "peerDependenciesMeta": {
+ "debug": {
+ "optional": true
+ }
+ }
+ },
"node_modules/for-each": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz",
@@ -3582,6 +3617,19 @@
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
},
+ "node_modules/http-proxy": {
+ "version": "1.18.1",
+ "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz",
+ "integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==",
+ "dependencies": {
+ "eventemitter3": "^4.0.0",
+ "follow-redirects": "^1.0.0",
+ "requires-port": "^1.0.0"
+ },
+ "engines": {
+ "node": ">=8.0.0"
+ }
+ },
"node_modules/human-id": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/human-id/-/human-id-4.0.0.tgz",
@@ -6424,6 +6472,11 @@
"node": ">=0.10.0"
}
},
+ "node_modules/requires-port": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
+ "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ=="
+ },
"node_modules/resolve": {
"version": "1.22.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz",
diff --git a/package.json b/package.json
index c57aec15d..55ba73e62 100644
--- a/package.json
+++ b/package.json
@@ -41,6 +41,7 @@
"@tiptap/starter-kit": "^2.0.0-beta.220",
"clsx": "^1.2.1",
"fuse.js": "^6.6.2",
+ "http-proxy": "^1.18.1",
"human-id": "^4.0.0",
"immer": "^9.0.19",
"lucide-react": "^0.130.1",
@@ -63,6 +64,7 @@
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.9",
+ "@types/http-proxy": "^1.17.10",
"@types/node": "^18.14.6",
"@types/randomcolor": "^0.5.7",
"@types/react": "^18.0.28",
diff --git a/pages/api/[...all].ts b/pages/api/[...all].ts
new file mode 100644
index 000000000..062ac419c
--- /dev/null
+++ b/pages/api/[...all].ts
@@ -0,0 +1,24 @@
+// import httpProxy from 'http-proxy'
+// import { NextApiRequest, NextApiResponse } from 'next'
+
+// export const config = {
+// api: {
+// // Enable `externalResolver` option in Next.js
+// externalResolver: true,
+// bodyParser: false,
+// },
+// }
+
+// async function handler(req: NextApiRequest, res: NextApiResponse) {
+// const url = new URL(req.url!, `http://${req.headers.host}`)
+
+// return new Promise((resolve, reject) => {
+// const proxy: httpProxy = httpProxy.createProxy()
+// proxy.once('proxyRes', resolve).once('error', reject).web(req, res, {
+// changeOrigin: true,
+// target: url.pathname === '/api/generate' ? process.env.API_URL : process.env.SUPABASE_URL,
+// })
+// })
+// }
+
+// export default handler
diff --git a/pages/api/project.ts b/pages/api/project.ts
index 38cf6cc9d..1bc56ee2f 100644
--- a/pages/api/project.ts
+++ b/pages/api/project.ts
@@ -148,4 +148,4 @@ async function handler(
return
}
-export default handler
\ No newline at end of file
+export default handler