Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ jobs:
NEXT_PUBLIC_DOCS_URL: ${{ secrets.NEXT_PUBLIC_DOCS_URL }}
SENTRY_DSN_DESKTOP: ${{ secrets.SENTRY_DSN_DESKTOP }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
STREAMS_URL: ${{ secrets.STREAMS_URL }}
run: bun run compile:app

- name: Build Electron app
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,3 @@ jobs:

- name: Build CLI and Desktop
run: bun turbo run build --filter=@superset/cli --filter=@superset/desktop
env:
STREAMS_URL: ${{ secrets.STREAMS_URL }}
1 change: 0 additions & 1 deletion .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ env:
ADMIN_ALIAS: admin-pr-${{ github.event.pull_request.number }}-superset.vercel.app
DOCS_ALIAS: docs-pr-${{ github.event.pull_request.number }}-superset.vercel.app
ELECTRIC_URL: https://superset-electric-pr-${{ github.event.pull_request.number }}.fly.dev/v1/shape
STREAMS_URL: https://superset-stream-pr-${{ github.event.pull_request.number }}.fly.dev

jobs:
deploy-database:
Expand Down
58 changes: 58 additions & 0 deletions apps/api/src/app/api/streams/[...path]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { auth } from "@superset/auth/server";
import { env } from "@/env";

export const maxDuration = 300;

const ALLOWED_HEADERS = [
"authorization",
"content-type",
"accept",
"x-actor-id",
];

function forwardHeaders(source: Headers): Headers {
const headers = new Headers();
for (const key of ALLOWED_HEADERS) {
const value = source.get(key);
if (value) {
headers.set(key, value);
}
}
return headers;
}

async function proxy(request: Request): Promise<Response> {
const sessionData = await auth.api.getSession({
headers: request.headers,
});
if (!sessionData?.user) {
return new Response("Unauthorized", { status: 401 });
}

const url = new URL(request.url);
const upstreamPath = url.pathname.replace(/^\/api\/streams/, "");
const upstream = new URL(`${env.STREAMS_URL}${upstreamPath}${url.search}`);

const headers = forwardHeaders(request.headers);

const hasBody = request.method !== "GET" && request.method !== "HEAD";

const response = await fetch(upstream, {
method: request.method,
headers,
body: hasBody ? request.body : undefined,
// @ts-expect-error -- Node fetch supports duplex for streaming request bodies
duplex: hasBody ? "half" : undefined,
});

return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: response.headers,
});
}

export const GET = proxy;
export const POST = proxy;
export const PUT = proxy;
export const DELETE = proxy;
1 change: 1 addition & 0 deletions apps/api/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const env = createEnv({
STRIPE_PRO_MONTHLY_PRICE_ID: z.string(),
STRIPE_PRO_YEARLY_PRICE_ID: z.string(),
SLACK_BILLING_WEBHOOK_URL: z.string().url(),
STREAMS_URL: z.string().url(),
SENTRY_AUTH_TOKEN: z.string().optional(),
},
client: {
Expand Down
4 changes: 0 additions & 4 deletions apps/desktop/electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ export default defineConfig({
"process.env.NEXT_PUBLIC_POSTHOG_HOST": defineEnv(
process.env.NEXT_PUBLIC_POSTHOG_HOST,
),
"process.env.STREAMS_URL": defineEnv(
process.env.STREAMS_URL,
"https://superset-stream.fly.dev",
),
},

build: {
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/trpc/routers/ai-chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const createAiChatRouter = () => {
getConfig: publicProcedure.query(async () => {
const { token } = await loadToken();
return {
proxyUrl: env.STREAMS_URL,
proxyUrl: `${env.NEXT_PUBLIC_API_URL}/api/streams`,
authToken: token,
};
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { loadToken } from "../../../auth/utils/auth-functions";
import { buildClaudeEnv } from "../auth";
import type { SessionStore } from "../session-store";

const PROXY_URL = env.STREAMS_URL;
const PROXY_URL = `${env.NEXT_PUBLIC_API_URL}/api/streams`;

function getClaudeBinaryPath(): string {
if (app.isPackaged) {
Expand Down
2 changes: 0 additions & 2 deletions apps/desktop/src/main/env.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const env = createEnv({
NEXT_PUBLIC_POSTHOG_KEY: z.string().optional(),
NEXT_PUBLIC_POSTHOG_HOST: z.string().default("https://us.i.posthog.com"),
SENTRY_DSN_DESKTOP: z.string().optional(),
STREAMS_URL: z.url().default("https://superset-stream.fly.dev"),
},

runtimeEnv: {
Expand All @@ -32,7 +31,6 @@ export const env = createEnv({
NEXT_PUBLIC_POSTHOG_KEY: process.env.NEXT_PUBLIC_POSTHOG_KEY,
NEXT_PUBLIC_POSTHOG_HOST: process.env.NEXT_PUBLIC_POSTHOG_HOST,
SENTRY_DSN_DESKTOP: process.env.SENTRY_DSN_DESKTOP,
STREAMS_URL: process.env.STREAMS_URL,
},
emptyStringAsUndefined: true,
// Only allow skipping validation in development (never in production)
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
- default-src 'self': Only allow resources from same origin
- script-src 'self' 'wasm-unsafe-eval' https://*.posthog.com: Allow scripts from same origin + WebAssembly (for xterm ImageAddon) + PostHog
- style-src 'self' 'unsafe-inline': Allow styles from same origin + inline (needed for CSS-in-JS)
- connect-src 'self' ws: wss: %NEXT_PUBLIC_API_URL% %STREAMS_URL% https://*.posthog.com https://*.sentry.io sentry-ipc:: Allow WebSocket + API (includes Electric proxy) + Durable Streams proxy + PostHog + Sentry
- connect-src 'self' ws: wss: %NEXT_PUBLIC_API_URL% https://*.posthog.com https://*.sentry.io sentry-ipc:: Allow WebSocket + API (includes Electric proxy + Streams proxy) + PostHog + Sentry
- img-src 'self' data: %NEXT_PUBLIC_API_URL% https://*.public.blob.vercel-storage.com https://github.com https://avatars.githubusercontent.com https://models.dev: Allow images from same origin + data URIs + API (Linear image proxy) + Vercel blob storage + GitHub avatars + model provider logos
- font-src 'self': Allow fonts from same origin
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'wasm-unsafe-eval' https://*.posthog.com; style-src 'self' 'unsafe-inline'; connect-src 'self' ws: wss: %NEXT_PUBLIC_API_URL% %STREAMS_URL% https://*.posthog.com https://*.sentry.io sentry-ipc:; img-src 'self' data: %NEXT_PUBLIC_API_URL% https://*.public.blob.vercel-storage.com https://github.com https://avatars.githubusercontent.com https://models.dev; font-src 'self';" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'wasm-unsafe-eval' https://*.posthog.com; style-src 'self' 'unsafe-inline'; connect-src 'self' ws: wss: %NEXT_PUBLIC_API_URL% https://*.posthog.com https://*.sentry.io sentry-ipc:; img-src 'self' data: %NEXT_PUBLIC_API_URL% https://*.public.blob.vercel-storage.com https://github.com https://avatars.githubusercontent.com https://models.dev; font-src 'self';" />
</head>

<body>
Expand Down
13 changes: 4 additions & 9 deletions apps/desktop/vite/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,10 @@ export function htmlEnvTransformPlugin(): Plugin {
return {
name: "html-env-transform",
transformIndexHtml(html) {
return html
.replace(
/%NEXT_PUBLIC_API_URL%/g,
process.env.NEXT_PUBLIC_API_URL || "https://api.superset.sh",
)
.replace(
/%STREAMS_URL%/g,
process.env.STREAMS_URL || "https://superset-stream.fly.dev",
);
return html.replace(
/%NEXT_PUBLIC_API_URL%/g,
process.env.NEXT_PUBLIC_API_URL || "https://api.superset.sh",
);
},
};
}
3 changes: 1 addition & 2 deletions turbo.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"POSTHOG_API_KEY",
"POSTHOG_PROJECT_ID",
"KV_REST_API_URL",
"KV_REST_API_TOKEN",
"STREAMS_URL"
"KV_REST_API_TOKEN"
],
"globalPassThroughEnv": [
"NODE_ENV",
Expand Down
Loading