Skip to content

[Feature Request] Add Support for t3-env package and backend static serving #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stychu opened this issue May 12, 2025 · 2 comments
Open

Comments

@stychu
Copy link

stychu commented May 12, 2025

I think this would be a great addition to options to choose from:

  1. Env handling
  2. If opted for separate backend/frontend setup an option to choose to have frontend being served via static bundle files instead of running two separate servers for frontend and backend
@AmanVarshney01
Copy link
Owner

  1. yes ill add t3 env addon very very soon
  2. can you explain this a bit more??

@stychu
Copy link
Author

stychu commented May 12, 2025

So given this scaffold -> pnpm create better-t-stack@latest my-better-t-app --yes --backend express --runtime node --api orpc --database none --orm none --no-auth --package-manager pnpm --no-git --addons biome

You’ll get a project with a separate backend (Express) and frontend (React), set up to use CORS by default. This is one valid approach.

Option 1: With CORS

  • The frontend and backend run on separate servers with CORS enabled.
  • This setup is useful if you want to deploy your React app to a CDN (like Vercel, Netlify, or S3) and your backend to a different server.
  • The frontend makes API requests directly to the backend, and CORS handles cross-origin requests.

Option 2: Without CORS (Proxy Setup)

  • You remove the CORS middleware from your Express backend.
  • During development, you set up a proxy in the Vite dev server so API requests go through the frontend server to the backend.
  • In production, you build the React app and serve the static files directly from the Express backend. Now, everything runs from a single server and origin, so CORS isn’t needed.

Summary:

  • Option 1 (CORS): Deploy frontend and backend separately (e.g., React on CDN, backend elsewhere).
  • Option 2 (Proxy, no CORS): Deploy only the backend; it serves both the API and the built frontend as static files. The whole app runs as one service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants