Skip to content

Commit 832923b

Browse files
authored
feat: CORS implementation, fix auth middleware (#2076)
1 parent 5f507a3 commit 832923b

16 files changed

Lines changed: 409 additions & 113 deletions

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ jobs:
6969
- run: bun install
7070
- uses: actions/download-artifact@v4
7171
with: { name: "build" }
72-
- run: bun --filter edge deploy --env=${{ inputs.environment || 'test' }}
72+
- run: bun wrangler deploy --env=${{ inputs.environment || 'test' }}
7373
if: ${{ false }}

.vscode/extensions.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22
"recommendations": [
3-
"arcanis.vscode-zipfs",
3+
"anthropic.claude-code",
4+
"bradlc.vscode-tailwindcss",
45
"dbaeumer.vscode-eslint",
5-
"eamodio.gitlens",
6+
"dbcode.dbcode",
67
"editorconfig.editorconfig",
78
"esbenp.prettier-vscode",
89
"github.copilot",
910
"github.vscode-github-actions",
10-
"graphql.vscode-graphql",
1111
"mikestead.dotenv",
12+
"oven.bun-vscode",
13+
"rphlmr.vscode-drizzle-orm",
1214
"streetsidesoftware.code-spell-checker",
1315
"vscode-icons-team.vscode-icons"
1416
]

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bun --cwd db studio # Open DB GUI
3939
bun --cwd db seed # Seed sample data
4040

4141
# Deployment
42-
bun --cwd edge deploy # Deploy to Cloudflare
42+
bun wrangler deploy --env=production
4343
```
4444

4545
## Code Conventions

README.md

Lines changed: 118 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
<a href="https://github.com/kriasoft/react-starter-kit/stargazers"><img src="https://img.shields.io/github/stars/kriasoft/react-starter-kit.svg?style=social&label=Star&maxAge=3600" height="20"></a>
66
<a href="https://twitter.com/koistya"><img src="https://img.shields.io/twitter/follow/koistya.svg?style=social&label=Follow&maxAge=3600" height="20"></a>
77

8-
So, you want to build a modern web app but don't want to spend the next two weeks configuring everything? You've come to the right place. This React Starter Kit is a batteries-included, production-ready boilerplate that lets you skip the boring parts and get straight to building.
8+
Building modern web applications shouldn't require weeks of configuration hell. This React Starter Kit eliminates the tedious setup work so you can focus on what matters: shipping great products.
99

10-
It's built on a modern, edge-first stack that's fast, type-safe, and frankly, a joy to work with. Whether you're building a weekend project or the next big thing, we've got your back.
10+
Designed for developers who value both speed and quality, this template provides a complete foundation for full-stack applications. From solo projects to team collaborations, it scales with your ambitions while maintaining the developer experience you deserve.
1111

12-
## Features
12+
## What You Get
1313

14-
- **Blazing Fast Everything**: Powered by [Bun](https://bun.sh/), from the backend server to the scripts. It's fast. Like, "go get a coffee and it's already done" fast.
15-
- **Full-Stack Type Safety**: With [TypeScript](https://www.typescriptlang.org/) and [tRPC](https://trpc.io/), you can say goodbye to runtime errors. If it compiles, it works (usually).
16-
- **Modern Frontend**: Built with [React 19](https://react.dev/), [TanStack Router](https://tanstack.com/router) for type-safe routing, and [Tailwind CSS v4](https://tailwindcss.com/) for styling. Your UI will be snappy and look good doing it.
17-
- **Edge-First Architecture**: Deploy to [Cloudflare Workers](https://workers.cloudflare.com/) for incredible performance and scalability. Your app will be everywhere, all at once.
18-
- **Database Included**: Comes with [Drizzle ORM](https://orm.drizzle.team/) and a pre-configured schema for multi-tenant applications. No more writing SQL by hand unless you really, really want to.
19-
- **Top-Notch DX**: Pre-configured with ESLint, Prettier, and VSCode settings to keep your code clean and your team happy. Less arguing about tabs vs. spaces, more building cool stuff.
14+
- **Performance by Default**: Bun runtime delivers exceptional speed across development and production. Your build times will thank you.
15+
- **Type Safety Throughout**: TypeScript and tRPC create an unbreakable contract between frontend and backend. Catch errors at compile time, not in production.
16+
- **Modern React Stack**: React 19 with TanStack Router provides type-safe navigation and powerful data fetching patterns. Tailwind CSS v4 handles styling with zero configuration.
17+
- **Edge-Native Deployment**: Cloudflare Workers ensure your app runs close to users worldwide. Experience sub-100ms response times globally.
18+
- **Database Ready**: Drizzle ORM with Cloudflare D1 provides a complete data layer. Multi-tenant support included out of the box.
19+
- **Developer Experience**: ESLint, Prettier, and VSCode configurations eliminate bikeshedding. Focus on features, not formatting.
2020

2121
<a href="https://reactstarter.com/s/1"><img src="https://reactstarter.com/s/1.png" height="60" /></a>&nbsp;&nbsp;<a href="https://reactstarter.com/s/2"><img src="https://reactstarter.com/s/2.png" height="60" /></a>&nbsp;&nbsp;<a href="https://reactstarter.com/s/3"><img src="https://reactstarter.com/s/3.png" height="60" /></a>
2222

@@ -25,75 +25,142 @@ It's built on a modern, edge-first stack that's fast, type-safe, and frankly, a
2525
This project was bootstrapped with [React Starter Kit](https://github.com/kriasoft/react-starter-kit).
2626
Be sure to join our [Discord channel](https://discord.com/invite/2nKEnKq) for assistance.
2727

28-
## Directory Structure
28+
## Monorepo Architecture
2929

30-
`├──`[`api`](./api) — tRPC API server built with [Hono](https://hono.dev/)<br>
31-
`├──`[`app`](./app) — Web application front-end built with [React](https://react.dev/) and [Tailwind CSS](https://tailwindcss.com/)<br>
32-
`├──`[`core`](./core) — Shared code, types, and WebSocket logic used across the stack<br>
33-
`├──`[`db`](./db) — Database schema, migrations, and seeds using [Drizzle ORM](https://orm.drizzle.team/)<br>
34-
`├──`[`edge`](./edge) — Cloudflare Worker entry point for handling requests at the edge<br>
35-
`├──`[`scripts`](./scripts) — Various build and automation scripts<br>
36-
`├──`[`tsconfig.base.json`](./tsconfig.base.json) — The common/shared TypeScript configuration for the monorepo<br>
37-
`└──`[`wrangler.jsonc`](./wrangler.jsonc) — Configuration file for Cloudflare Workers<br>
30+
This starter kit uses a thoughtfully organized monorepo structure that promotes code reuse and maintainability:
3831

39-
## Tech Stack
32+
`├──`[`app/`](./app) — React frontend with Vite, TanStack Router, and Tailwind CSS<br>
33+
`├──`[`api/`](./api) — tRPC API server powered by Hono framework<br>
34+
`├──`[`edge/`](./edge) — Cloudflare Workers entry point and edge logic<br>
35+
`├──`[`core/`](./core) — Shared TypeScript types and utilities<br>
36+
`├──`[`db/`](./db) — Database schemas, migrations, and seed data<br>
37+
`├──`[`scripts/`](./scripts) — Build automation and development tools<br>
4038

41-
- **Runtime**: [Bun](https://bun.sh/)
42-
- **Platform**: [Cloudflare Workers](https://workers.cloudflare.com/)
43-
- **Frameworks**: [React 19](https://react.dev/), [Hono](https://hono.dev/)
44-
- **API**: [tRPC](https://trpc.io/)
45-
- **Routing**: [TanStack Router](https://tanstack.com/router)
46-
- **Database**: [Drizzle ORM](https://orm.drizzle.team/) with [Cloudflare D1](https://developers.cloudflare.com/d1/)
47-
- **Styling**: [Tailwind CSS v4](https://tailwindcss.com/), [ShadCN UI](https://ui.shadcn.com/)
48-
- **State Management**: [Jotai](https://jotai.org/)
49-
- **Authentication**: [Better Auth](https://www.better-auth.com/)
50-
- **Tooling**: [Vite](https://vitejs.dev/), [Vitest](https://vitest.dev/), [TypeScript](https://www.typescriptlang.org/), [ESLint](https://eslint.org/), [Prettier](https://prettier.io/)
39+
**Why Monorepo?** This structure enables seamless code sharing between frontend and backend, ensures type consistency across your entire stack, and simplifies dependency management. When you update a type definition, both client and server stay in sync automatically.
5140

52-
## Requirements
41+
## Perfect For
5342

54-
- [Bun](https://bun.sh/) (v1.0 or newer)
55-
- [VS Code](https://code.visualstudio.com/) editor with our [recommended extensions](.vscode/extensions.json)
56-
- Optionally, the [React Developer Tools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en) for your browser.
43+
- **SaaS Applications**: Multi-tenant architecture with user management built-in
44+
- **API-First Products**: tRPC provides excellent developer experience for API development
45+
- **Global Applications**: Edge deployment ensures fast loading times worldwide
46+
- **Team Projects**: Monorepo structure scales well with multiple developers
47+
- **Rapid Prototyping**: Skip configuration and start building features immediately
5748

58-
## Getting Started
49+
## Technology Stack
5950

60-
[Generate](https://github.com/kriasoft/react-starter-kit/generate) a new project
61-
from this template, clone it, install project dependencies, update the
62-
environment variables found in [`.env`](./.env) / [`.env.local`](./.env.local), and start hacking:
51+
**Core Runtime & Platform**
52+
53+
- [Bun](https://bun.sh/) — Lightning-fast JavaScript runtime and package manager
54+
- [Cloudflare Workers](https://workers.cloudflare.com/) — Edge computing platform
55+
56+
**Frontend & UI**
57+
58+
- [React 19](https://react.dev/) — Latest React with concurrent features
59+
- [TanStack Router](https://tanstack.com/router) — Type-safe routing with data loading
60+
- [Tailwind CSS v4](https://tailwindcss.com/) — Utility-first CSS framework
61+
- [ShadCN UI](https://ui.shadcn.com/) — Beautiful, accessible components
62+
- [Jotai](https://jotai.org/) — Atomic state management
63+
64+
**Backend & API**
65+
66+
- [Hono](https://hono.dev/) — Ultrafast web framework for the edge
67+
- [tRPC](https://trpc.io/) — End-to-end type safety for APIs
68+
- [Better Auth](https://www.better-auth.com/) — Modern authentication solution
69+
70+
**Database & ORM**
71+
72+
- [Drizzle ORM](https://orm.drizzle.team/) — TypeScript ORM with excellent DX
73+
- [Cloudflare D1](https://developers.cloudflare.com/d1/) — Serverless SQLite database
74+
75+
**Development Tools**
76+
77+
- [Vite](https://vitejs.dev/) — Next-generation frontend tooling
78+
- [Vitest](https://vitest.dev/) — Blazing fast unit testing
79+
- [TypeScript](https://www.typescriptlang.org/) — Static type checking
80+
- [ESLint](https://eslint.org/) & [Prettier](https://prettier.io/) — Code quality and formatting
81+
82+
## Prerequisites
83+
84+
- [Bun](https://bun.sh/) v1.2+ (replaces Node.js and npm)
85+
- [VS Code](https://code.visualstudio.com/) with our [recommended extensions](.vscode/extensions.json)
86+
- [React Developer Tools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en) browser extension (recommended)
87+
- [Cloudflare account](https://dash.cloudflare.com/sign-up) for deployment
88+
89+
## Quick Start
90+
91+
### 1. Create Your Project
92+
93+
[Generate a new repository](https://github.com/kriasoft/react-starter-kit/generate) from this template, then clone it locally:
6394

6495
```bash
65-
# Clone the repository
66-
git clone https://github.com/kriasoft/react-starter-kit.git example
67-
cd ./example
96+
git clone https://github.com/your-username/your-project-name.git
97+
cd your-project-name
98+
```
99+
100+
### 2. Install Dependencies
101+
102+
```bash
103+
bun install
104+
```
68105

69-
# Launch the front-end app
106+
### 3. Configure Environment
107+
108+
Update environment variables in [`.env`](./.env) and `.env.local` files as well as Wrangler configuration in [`wrangler.jsonc`](./wrangler.jsonc).
109+
110+
### 4. Start Development
111+
112+
Open two terminals and run these commands:
113+
114+
**Terminal 1 - Frontend:**
115+
116+
```bash
70117
bun --cwd app start
118+
```
119+
120+
**Terminal 2 - Backend:**
71121

72-
# Launch the backend API server
122+
```bash
73123
bun --cwd edge build --watch
74124
bun wrangler dev
125+
```
75126

76-
# Migrate the database
127+
### 5. Initialize Database
128+
129+
```bash
130+
# Let Wrangler create the D1 database locally
131+
bun wrangler d1 execute db --local --command "SELECT 1"
132+
# Apply database schema and migrations
77133
bun --cwd db migrate
134+
bun --cwd db seed # Optional: add sample data
78135
```
79136

80-
Your frontend will be running at <http://localhost:5173/>, and the backend API will be on the port from `wrangler dev` (usually 8787). Open the frontend URL in your browser to see the app in action.
81-
82-
## How to Deploy
137+
Open <http://localhost:5173> to see your app running. The backend API will be available at the port shown by `wrangler dev` (typically 8787).
83138

84-
Ensure that all the environment variables in `.env`/`.env.local` files and Wrangler configuration in `wrangler.json` file are up-to-date.
139+
## Production Deployment
85140

86-
If you haven't done it already, push any secret values you may need to CF Workers
87-
environment by running `bun wrangler secret put <NAME> [--env #0]`.
141+
### 1. Environment Setup
88142

89-
Finally build and deploy the app by running:
143+
Ensure your production environment variables are configured:
90144

145+
```bash
146+
# Set secrets in Cloudflare Workers
147+
bun wrangler secret put BETTER_AUTH_SECRET --env=production
148+
bun wrangler secret put OPENAI_API_KEY --env=production
91149
```
150+
151+
### 2. Build and Deploy
152+
153+
```bash
154+
# Build all packages
92155
bun --cwd app build
93156
bun --cwd edge build
94-
bun wrangler deploy
157+
158+
# Deploy to Cloudflare Workers
159+
bun wrangler deploy --env=production
95160
```
96161

162+
Your application will be live on your Cloudflare Workers domain within seconds. The edge-first architecture ensures optimal performance regardless of user location.
163+
97164
## Contributors 👨‍💻
98165

99166
<a href="https://reactstarter.com/c/1"><img src="https://reactstarter.com/c/1.png" height="60" /></a>&nbsp;&nbsp;<a href="https://reactstarter.com/c/2"><img src="https://reactstarter.com/c/2.png" height="60" /></a>&nbsp;&nbsp;<a href="https://reactstarter.com/c/3"><img src="https://reactstarter.com/c/3.png" height="60" /></a>&nbsp;&nbsp;<a href="https://reactstarter.com/c/4"><img src="https://reactstarter.com/c/4.png" height="60" /></a>&nbsp;&nbsp;<a href="https://reactstarter.com/c/5"><img src="https://reactstarter.com/c/5.png" height="60" /></a>&nbsp;&nbsp;<a href="https://reactstarter.com/c/6"><img src="https://reactstarter.com/c/6.png" height="60" /></a>&nbsp;&nbsp;<a href="https://reactstarter.com/c/7"><img src="https://reactstarter.com/c/7.png" height="60" /></a>&nbsp;&nbsp;<a href="https://reactstarter.com/c/8"><img src="https://reactstarter.com/c/8.png" height="60" /></a>

bun.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/tsconfig.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
"tsBuildInfoFile": "./dist/.tsbuildinfo",
99
"types": ["@cloudflare/workers-types", "bun"]
1010
},
11-
"include": ["**/*.ts", "**/*.json", "./types/cloudflare-env.d.ts"],
11+
"include": [
12+
"**/*.ts",
13+
"**/*.json",
14+
"./types/cloudflare-env.d.ts",
15+
"./types/cloudflare-env-overrides.d.ts"
16+
],
1217
"exclude": ["**/dist/**/*", "**/node_modules/**/*"]
1318
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* SPDX-FileCopyrightText: 2014-present Kriasoft */
2+
/* SPDX-License-Identifier: MIT */
3+
4+
declare namespace Cloudflare {
5+
interface Env {
6+
// Override generated union types to be more flexible for runtime processing
7+
ALLOWED_ORIGINS?: string;
8+
ENVIRONMENT?: "development" | "production" | "preview";
9+
10+
// Secret bindings are not generated by `wrangler types`
11+
BETTER_AUTH_SECRET: string;
12+
GOOGLE_CLIENT_ID: string;
13+
GOOGLE_CLIENT_SECRET: string;
14+
OPENAI_API_KEY: string;
15+
}
16+
}

core/types/cloudflare-env.d.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
/* eslint-disable */
2-
// Generated by Wrangler by running `wrangler types --include-runtime=false core/types/cloudflare-env.d.ts` (hash: 5aff64c6380a800007b09f3b8a2d171b)
2+
// Generated by Wrangler by running `wrangler types --include-runtime=false core/types/cloudflare-env.d.ts` (hash: e0db57e983f465e65b6f48768e3d5c45)
33
declare namespace Cloudflare {
44
interface Env {
5-
ENV: "production";
5+
ENVIRONMENT: "development" | "production" | "preview";
6+
ALLOWED_ORIGINS:
7+
| "http://localhost:5173,http://127.0.0.1:5173"
8+
| "https://example.com"
9+
| "https://preview.example.com";
610
db: D1Database;
711
ASSETS: Fetcher;
812
}
@@ -14,5 +18,8 @@ type StringifyValues<EnvType extends Record<string, unknown>> = {
1418
: string;
1519
};
1620
declare namespace NodeJS {
17-
interface ProcessEnv extends StringifyValues<Pick<Cloudflare.Env, "ENV">> {}
21+
interface ProcessEnv
22+
extends StringifyValues<
23+
Pick<Cloudflare.Env, "ENVIRONMENT" | "ALLOWED_ORIGINS">
24+
> {}
1825
}

core/types/index.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
/* SPDX-FileCopyrightText: 2014-present Kriasoft */
22
/* SPDX-License-Identifier: MIT */
33

4-
import type { Session } from "better-auth/types";
4+
import type { Session, User } from "better-auth/types";
55

6-
export type CloudflareEnv = Cloudflare.Env & {
7-
// Cloudflare Workers secret bindings
8-
BETTER_AUTH_SECRET: string;
9-
GOOGLE_CLIENT_ID: string;
10-
GOOGLE_CLIENT_SECRET: string;
11-
OPENAI_API_KEY: string;
12-
};
6+
export type CloudflareEnv = Cloudflare.Env;
137

148
export type CloudflareVariables = {
159
session?: Session | null;
10+
user?: User | null;
1611
};

0 commit comments

Comments
 (0)