TanStackT
TanStack7mo ago
16 replies
then-purple

Deploying built assets to CDN/S3

I run a pretty big site and we're slowly implementing TanStack Start on it.

We have around 8 web boxes in a load balancer, and the way we typically handle deploys is we build the the app on every one of those boxes, and have a copy of client-side assets/modules on S3.

This allows us to properly leverage Cloudflare caching and whatnot for the user, while still allowing all server-side JS to run on the box properly.

I've kinda got it working by specifying the base option in vite.config.js, and then kind of "undoing" that in nitro.config.ts by setting runtimeConfig.app.baseURL to / so that it still uses / for server stuff, but the S3 URL for vite public asset paths.

That more or less works, but it feels pretty "hacky"? I guess. In addition, the <link preload= scripts added to the html have misformated URLs: http:/<cdn>/<asset> (notice one slash after http: and not two), this is due to the use of path.join(APP_BASE.. vs. joinURL in the start-plugin-core and that causes 404s for the user.

Can go more in detail if anyone from the TS team is willing to lend some input, but basically just trying to understand if there's a more stable kind of first party way of doing this.
Was this page helpful?