This repository demonstrates a simple Single Page Application (SPA) built with React and TypeScript, powered by the serverless framework Hono and deployed on Cloudflare Pages.
This template provides a minimal setup to get you started with:
- React: The front-end framework for building dynamic user interfaces.
- TypeScript: A superset of JavaScript that adds optional static typing for improved code quality.
- Vite: A fast development server and build tool for modern web development.
- Hono: A lightweight, minimal and fast serverless web framework for Deno and Cloudflare Workers.
- Cloudflare Pages: A platform for hosting static websites and serverless functions.
- TanStack Router: A performant and powerful routing library for React.
The project structure is organized as follows:
app/
: Contains the source code for both the client and the API.api/
: Hono API code (app/api/index.tsx
)main.tsx
: Entry point for the React application (app/main.tsx
)routes/
: React Router routes (e.g.,app/routes/__root.tsx
,app/routes/about.lazy.tsx
,app/routes/index.lazy.tsx
)style.css
: Tailwind CSS stylesheet (app/style.css
)components/
: React components (e.g.,app/components/notion-like-editor.tsx
)
vite.config.ts
: Vite configuration file (vite.config.ts
)tailwind.config.js
: Tailwind CSS configuration file (tailwind.config.js
)tsconfig.app.json
: TypeScript configuration file for the application (tsconfig.app.json
)tsconfig.json
: TypeScript configuration file for the entire project (tsconfig.json
)tsconfig.node.json
: TypeScript configuration file for Node.js (tsconfig.node.json
)package.json
: Project dependencies and scripts (package.json
)_routes.json
: Hono routes configuration for Cloudflare Pages (_routes.json
)index.html
: HTML template for the React application (index.html
)README.md
: This file! (README.md
)LICENSE
: MIT license (LICENSE
)
-
Clone the repository:
git clone https://github.com/laiso/hono-spa-react.git cd hono-spa-react
-
Install dependencies:
npm install
-
Start development server:
npm run dev
This will start two servers:
- Client: Runs on
http://localhost:5173/
and serves the React application. - API: Runs on
http://localhost:3000/api
and serves the Hono API.
- Client: Runs on
-
Build for production:
npm run build
This will generate optimized build artifacts in the
dist
directory.
-
Deploy to Cloudflare Pages:
npm run deploy
This will deploy the built application to your Cloudflare Pages account.
This template uses Clerk for authentication. To get started, sign up for a free account and create a new project. Then, update the following environment variables in the .env
file:
# development
export CLERK_PUBLISHABLE_KEY=pk_test_XXX
export CLERK_SECRET_KEY=sk_test_XXX
# production
npx wrangler secret put CLERK_PUBLISHABLE_KEY
npx wrangler secret put CLERK_SECRET_KEY
Clerk documentation is available at:
For production applications, consider updating the ESLint configuration to enable type-aware lint rules:
-
tsconfig.json
: Configure theparserOptions
property to point to your TypeScript configuration files:{ "parserOptions": { "ecmaVersion": "latest", "sourceType": "module", "project": ["./tsconfig.json", "./tsconfig.node.json"], "tsconfigRootDir": __dirname } }
-
.eslintrc.cjs
: Replaceplugin:@typescript-eslint/recommended
with one of these options for type-checked linting:plugin:@typescript-eslint/recommended-type-checked
plugin:@typescript-eslint/strict-type-checked
- Optionally, add
plugin:@typescript-eslint/stylistic-type-checked
-
Install
eslint-plugin-react
:npm install eslint-plugin-react
-
.eslintrc.cjs
: Addplugin:react/recommended
andplugin:react/jsx-runtime
to theextends
list.
Contributions are welcome! Please open an issue or a pull request if you have any suggestions or improvements.
This project is licensed under the MIT License. See LICENSE
for more details.