A modern, full-stack web application template combining the power of SvelteKit frontend with Hono API backend, optimized for deployment on Cloudflare Workers.
npm install -g wrangler
Clone the repository
git clone <your-repo-url>
cd sveltekit-hono
Install dependencies
pnpm install
Set up environment variables
cp .env.example .env.local
Start development server
pnpm dev
Open your browser Visit http://localhost:5173
Command | Description |
---|---|
pnpm dev |
Start SvelteKit development server |
pnpm dev:cf |
Start Cloudflare Workers development server |
pnpm build |
Build for production |
pnpm preview |
Preview production build locally |
pnpm preview:cf |
Preview with Cloudflare Workers simulation |
pnpm deploy |
Deploy to Cloudflare Workers |
pnpm deploy:cf |
Deploy to Cloudflare production environment |
pnpm check |
Run TypeScript and Svelte checks |
pnpm lint |
Lint code with ESLint and Prettier |
pnpm format |
Format code with Prettier |
For Frontend Development:
pnpm dev # Fastest hot reload, recommended for UI work
For Full-Stack with Cloudflare Simulation:
pnpm dev:cf # Test with Cloudflare Workers environment
The Hono API provides the following endpoints:
Method | Endpoint | Description |
---|---|---|
GET |
/api/health |
Health check and environment info |
GET |
/api/hello |
Basic hello endpoint with request info |
GET |
/api/users |
Get all users (demo data) |
POST |
/api/users |
Create a new user |
PUT |
/api/users/:id |
Update user by ID |
DELETE |
/api/users/:id |
Delete user by ID |
// Fetch users
const response = await fetch('/api/users');
const { users } = await response.json();
// Create user
const newUser = await fetch('/api/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'John Doe', email: '[email protected]' })
});
āāā src/
ā āāā routes/
ā ā āāā +page.svelte # Main demo page
ā ā āāā +layout.svelte # App layout
ā ā āāā api/
ā ā āāā [...paths]/
ā ā āāā +server.ts # Hono API server
ā āāā lib/
ā ā āāā env.ts # Environment configuration
ā āāā models/
ā ā āāā user.model.ts # TypeScript models
ā āāā types/
ā ā āāā health.ts # Type definitions
ā āāā app.html # HTML template
ā āāā app.css # Global styles
āāā static/ # Static assets
āāā wrangler.toml # Cloudflare Workers config
āāā svelte.config.js # SvelteKit configuration
āāā vite.config.ts # Vite configuration
āāā DEVELOPMENT.md # Detailed development guide
Login to Cloudflare
wrangler login
Deploy to development
pnpm deploy
Deploy to production
pnpm deploy:cf
Configure your environment variables in:
.env.local
wrangler.toml
# wrangler.toml
[vars]
ENVIRONMENT = "development"
[env.production.vars]
ENVIRONMENT = "production"
# .env.local
ENVIRONMENT=development
API_BASE_URL=http://localhost:5173/api
CF_PAGES_URL=https://localhost:8787
The application is optimized for Cloudflare Workers with:
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)API routes not working in production?
wrangler.toml
configuration+server.ts
Environment variables not accessible?
PUBLIC_
wrangler.toml
Build errors?
pnpm check
for TypeScript validationFor more troubleshooting tips, see DEVELOPMENT.md.
This project is licensed under the MIT License - see the LICENSE file for details.
Give a āļø if this project helped you!
Built with ā¤ļø using SvelteKit, Hono, and Cloudflare Workers