Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Clean up

Jakub Novakb72817d0886a
diff --git a/apps/web/src/app/(dashboard)/dashboard/utils.ts b/apps/web/src/app/(dashboard)/dashboard/utils.ts
index 0b8e81e95..c581e6d6a 100644
--- a/apps/web/src/app/(dashboard)/dashboard/utils.ts
+++ b/apps/web/src/app/(dashboard)/dashboard/utils.ts
@@ -1,27 +1,31 @@
-export function getBaseUrl(domain: string) {
+function getUrl(domain: string, subdomain: string, path: string) {
let url = domain
+ const local = domain.startsWith('localhost') || domain.startsWith('127.0.0.')
+
if (!domain.startsWith('http')) {
- const local = domain === 'localhost' || domain.startsWith('127.0.0.')
url = `http${local ? '' : 's'}://${domain}`
}
const parsedUrl = new URL(url)
- return parsedUrl.toString()
-}
-
-export function getBillingUrl(domain: string) {
- let url = domain
- const local = domain === 'localhost' || domain.startsWith('127.0.0.')
-
- if (!domain.startsWith('http')) {
- url = `http${local ? '' : 's'}://${domain}`
+ if (path) {
+ const decodedUrl = decodeURIComponent(path)
+ const [pathname, queryString] = decodedUrl.split('?')
+ parsedUrl.pathname = pathname
+ if (queryString) parsedUrl.search = queryString
}
- const parsedUrl = new URL(url)
if (!local) {
- parsedUrl.hostname = `billing.${parsedUrl.hostname}`
+ parsedUrl.hostname = `${subdomain}.${parsedUrl.hostname}`
}
return parsedUrl.toString()
}
+
+export function getAPIUrl(domain: string, path: string) {
+ return getUrl(domain, 'api', path)
+}
+
+export function getBillingUrl(domain: string, path: string) {
+ return getUrl(domain, 'billing', path)
+}
diff --git a/apps/web/src/components/Dashboard/Billing.tsx b/apps/web/src/components/Dashboard/Billing.tsx
index 72373e468..65e7c6c13 100644
--- a/apps/web/src/components/Dashboard/Billing.tsx
+++ b/apps/web/src/components/Dashboard/Billing.tsx
@@ -42,7 +42,7 @@ export const BillingContent = ({
const getInvoices = async function getInvoices() {
setInvoices([])
const res = await fetch(
- `${getBillingUrl(domain)}/teams/${team.id}/invoices`,
+ getBillingUrl(domain, `/teams/${team.id}/invoices`),
{
headers: {
'X-Team-API-Key': team.apiKeys[0],
@@ -60,7 +60,7 @@ export const BillingContent = ({
setCredits(null)
const creditsRes = await fetch(
- `${getBillingUrl(domain)}/teams/${team.id}/usage`,
+ getBillingUrl(domain, `/teams/${team.id}/usage`),
{
headers: {
'X-Team-API-Key': team.apiKeys[0],
diff --git a/apps/web/src/components/Dashboard/Developer.tsx b/apps/web/src/components/Dashboard/Developer.tsx
index 7896e8795..6898c944d 100644
--- a/apps/web/src/components/Dashboard/Developer.tsx
+++ b/apps/web/src/components/Dashboard/Developer.tsx
@@ -39,9 +39,6 @@ export const DeveloperContent = ({
hostParts = hostParts.slice(1)
}
setDomain(hostParts.join('.'))
- } else {
- console.log('Invalid URL')
- setDomain('Invalid URL')
}
}
diff --git a/apps/web/src/components/Dashboard/Keys.tsx b/apps/web/src/components/Dashboard/Keys.tsx
index b4fa43ce7..e5beec49b 100644
--- a/apps/web/src/components/Dashboard/Keys.tsx
+++ b/apps/web/src/components/Dashboard/Keys.tsx
@@ -64,7 +64,7 @@ export const KeysContent = ({
useEffect(() => {
async function fetchApiKeys() {
const res = await fetch(
- `${getBillingUrl(domain)}/teams/${currentTeam.id}/api-keys`,
+ getBillingUrl(domain, `/teams/${currentTeam.id}/api-keys`),
{
headers: {
'X-USER-ACCESS-TOKEN': user.accessToken,
@@ -98,9 +98,10 @@ export const KeysContent = ({
}
const res = await fetch(
- `${getBillingUrl(domain)}/teams/${currentTeam.id}/api-keys/${
- currentKey?.id
- }`,
+ getBillingUrl(
+ domain,
+ `/teams/${currentTeam.id}/api-keys/${currentKey?.id}`
+ ),
{
method: 'DELETE',
headers: {
@@ -123,7 +124,7 @@ export const KeysContent = ({
async function createApiKey() {
const res = await fetch(
- `${getBillingUrl(domain)}/teams/${currentTeam.id}/api-keys`,
+ getBillingUrl(domain, `/teams/${currentTeam.id}/api-keys`),
{
method: 'POST',
headers: {
@@ -155,9 +156,10 @@ export const KeysContent = ({
async function updateApiKey() {
const res = await fetch(
- `${getBillingUrl(domain)}/teams/${currentTeam.id}/api-keys/${
- currentKey?.id
- }`,
+ getBillingUrl(
+ domain,
+ `/teams/${currentTeam.id}/api-keys/${currentKey?.id}`
+ ),
{
method: 'PATCH',
headers: {
diff --git a/apps/web/src/components/Dashboard/Personal.tsx b/apps/web/src/components/Dashboard/Personal.tsx
index 85b4c5b66..f66d01b6d 100644
--- a/apps/web/src/components/Dashboard/Personal.tsx
+++ b/apps/web/src/components/Dashboard/Personal.tsx
@@ -34,7 +34,7 @@ export const PersonalContent = ({
}
const updateUserEmail = async () => {
- const res = await fetch(`${getBillingUrl(domain)}/users`, {
+ const res = await fetch(getBillingUrl(domain, '/users'), {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
diff --git a/apps/web/src/components/Dashboard/Sandboxes.tsx b/apps/web/src/components/Dashboard/Sandboxes.tsx
index 50569fc84..dc6165bb7 100644
--- a/apps/web/src/components/Dashboard/Sandboxes.tsx
+++ b/apps/web/src/components/Dashboard/Sandboxes.tsx
@@ -10,7 +10,7 @@ import {
import { useState } from 'react'
import { useEffect } from 'react'
import { Team } from '@/utils/useUser'
-import { getBaseUrl } from '@/app/(dashboard)/dashboard/utils'
+import { getAPIUrl } from '@/app/(dashboard)/dashboard/utils'
interface Sandbox {
alias: string
@@ -105,7 +105,7 @@ async function fetchSandboxes(
domain: string,
apiKey: string
): Promise<Sandbox[]> {
- const res = await fetch(`${getBaseUrl(domain)}/sandboxes`, {
+ const res = await fetch(getAPIUrl(domain, '/sandboxes'), {
method: 'GET',
headers: {
'X-API-KEY': apiKey,
diff --git a/apps/web/src/components/Dashboard/Team.tsx b/apps/web/src/components/Dashboard/Team.tsx
index 0171c72da..02aa56a59 100644
--- a/apps/web/src/components/Dashboard/Team.tsx
+++ b/apps/web/src/components/Dashboard/Team.tsx
@@ -66,7 +66,7 @@ export const TeamContent = ({
useEffect(() => {
const getTeamMembers = async () => {
const res = await fetch(
- `${getBillingUrl(domain)}/teams/${team.id}/users`,
+ getBillingUrl(domain, `/teams/${team.id}/users`),
{
headers: {
'X-User-Access-Token': user.accessToken,
@@ -105,7 +105,7 @@ export const TeamContent = ({
}
const deleteUserFromTeam = async () => {
- const res = await fetch(`${getBillingUrl(domain)}/teams/${team.id}/users`, {
+ const res = await fetch(getBillingUrl(domain, `/teams/${team.id}/users`), {
method: 'DELETE',
headers: {
'X-User-Access-Token': user.accessToken,
@@ -128,7 +128,7 @@ export const TeamContent = ({
}
const changeTeamName = async () => {
- const res = await fetch(`${getBillingUrl(domain)}/teams/${team.id}`, {
+ const res = await fetch(getBillingUrl(domain, `/teams/${team.id}`), {
headers: {
'X-Team-API-Key': team.apiKeys[0],
'Content-Type': 'application/json',
@@ -165,7 +165,7 @@ export const TeamContent = ({
return
}
- const res = await fetch(`${getBillingUrl(domain)}/teams/${team.id}/users`, {
+ const res = await fetch(getBillingUrl(domain, `/teams/${team.id}/users`), {
headers: {
'X-User-Access-Token': user.accessToken,
'Content-Type': 'application/json',
diff --git a/apps/web/src/components/Dashboard/Templates.tsx b/apps/web/src/components/Dashboard/Templates.tsx
index a1bcdd573..85c0a0337 100644
--- a/apps/web/src/components/Dashboard/Templates.tsx
+++ b/apps/web/src/components/Dashboard/Templates.tsx
@@ -28,7 +28,7 @@ import {
AlertDialogAction,
} from '../ui/alert-dialog'
import { toast } from '../ui/use-toast'
-import { getBaseUrl } from '@/app/(dashboard)/dashboard/utils'
+import { getAPIUrl } from '@/app/(dashboard)/dashboard/utils'
interface Template {
aliases: string[]
@@ -78,7 +78,7 @@ export function TemplatesContent({
async function deleteTemplate(domain: string) {
const res = await fetch(
- `${getBaseUrl(domain)}/templates/${currentTemplate?.templateID}`,
+ getAPIUrl(domain, `/templates/${currentTemplate?.templateID}`),
{
method: 'DELETE',
headers: {
@@ -105,7 +105,7 @@ export function TemplatesContent({
async function publishTemplate(domain: string) {
const res = await fetch(
- `${getBaseUrl(domain)}/templates/${currentTemplate?.templateID}`,
+ getAPIUrl(domain, `/templates/${currentTemplate?.templateID}`),
{
method: 'PATCH',
headers: {
@@ -306,7 +306,7 @@ async function fetchTemplates(
accessToken: string,
teamId: string
): Promise<Template[]> {
- const res = await fetch(`${getBaseUrl(domain)}/templates?teamID=${teamId}`, {
+ const res = await fetch(getAPIUrl(domain, `templates?teamID=${teamId}`), {
method: 'GET',
headers: {
Authorization: `Bearer ${accessToken}`,
diff --git a/apps/web/src/components/Dashboard/Usage.tsx b/apps/web/src/components/Dashboard/Usage.tsx
index 9f3961943..23d151c2e 100644
--- a/apps/web/src/components/Dashboard/Usage.tsx
+++ b/apps/web/src/components/Dashboard/Usage.tsx
@@ -47,7 +47,7 @@ export const UsageContent = ({
setCostUsage([])
const response = await fetch(
- `${getBillingUrl(domain)}/teams/${team.id}/usage`,
+ getBillingUrl(domain, `/teams/${team.id}/usage`),
{
headers: {
'X-Team-API-Key': team.apiKeys[0],
diff --git a/apps/web/src/components/Pricing/SwitchToProButton.tsx b/apps/web/src/components/Pricing/SwitchToProButton.tsx
index dd38f75c1..4d5fc4819 100644
--- a/apps/web/src/components/Pricing/SwitchToProButton.tsx
+++ b/apps/web/src/components/Pricing/SwitchToProButton.tsx
@@ -20,7 +20,7 @@ function createCheckout(domain: string, tierID: string, teamID: string) {
})
}
- return fetch(`${getBillingUrl(domain)}/checkouts`, {
+ return fetch(getBillingUrl(domain, '/checkouts'), {
method: 'POST',
headers: {
'Content-Type': 'application/json',