Files
otunes/apps/web/proxy.server.ts
T
joshuafhigginsandClaude Opus 5.5 Verified 37d1195955 feat(web): support downloads in the static export
Main's download routes are server-only like the other API routes. They
take the session from a `token` parameter, the options POST is allowed
cross-origin, and the client fetches songs and covers from the picked
server. The service worker matches downloaded covers from any origin,
and skips offline page caching in exports since they are served locally.
pnpm 12 fails on ignored build scripts, so electron-winstaller's is
denied explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 00:19:18 -05:00

51 lines
1.3 KiB
TypeScript

import {
convexAuthNextjsMiddleware,
createRouteMatcher,
nextjsMiddlewareRedirect,
} from "@convex-dev/auth/nextjs/server"
import { getConvexServerUrl } from "@/lib/convex-server"
const isAuthPage = createRouteMatcher(["/signin", "/signup"])
const isPublic = createRouteMatcher([
// Song routes check the session themselves, from the cookie or a `token`
// query parameter (static exports on another origin).
"/api/song/(.*)",
"/api/download/options",
"/api/album/:id/cover",
"/api/artist/:id/cover",
"/api/playlist/:id/cover",
// Mobile clients load avatars without the web auth cookie.
"/api/user/:id/avatar",
"/album",
"/album/:id",
"/artist",
"/artist/:id",
"/playlist",
"/playlist/:id",
])
const authMiddleware = convexAuthNextjsMiddleware(
async (request, { convexAuth }) => {
if (isPublic(request)) {
return
}
const authenticated = await convexAuth.isAuthenticated()
if (isAuthPage(request) && authenticated) {
return nextjsMiddlewareRedirect(request, "/")
}
if (!isAuthPage(request) && !authenticated) {
return nextjsMiddlewareRedirect(request, "/signin")
}
},
{ convexUrl: getConvexServerUrl() }
)
export default authMiddleware
export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
}