Skip to content

Commit 8194995

Browse files
authored
Add low-dependency HTTP server template (#38)
1 parent 6111f43 commit 8194995

26 files changed

Lines changed: 1388 additions & 1 deletion

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- [2026-01-09] [Reconcile changelog](https://github.com/rubriclab/create-rubric-app/commit/65c2411412e1873ba12b0b45ff7e9c36babf3407)
12
- [2025-12-22] [Correct example env](https://github.com/rubriclab/create-rubric-app/commit/c7200451c9d2cac4338bc7ddd2f0a66b7bd7b55e)
23
- [2025-12-19] [Fix build](https://github.com/rubriclab/create-rubric-app/commit/c78aa752e2b9eb8eec685670e610ea85d8821a3b)
34
- [2025-12-19] [Fix build](https://github.com/rubriclab/create-rubric-app/commit/f25fb6f2540c82df6e030a1a0dfdebd951a99b60)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
"simple-git-hooks": {
3333
"post-commit": "bun x @rubriclab/package post-commit"
3434
},
35-
"version": "1.6.32"
35+
"version": "1.6.33"
3636
}

templates/react/.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# dependencies
2+
node_modules
3+
4+
# output
5+
out
6+
dist
7+
generated
8+
9+
# logs
10+
logs
11+
12+
# dotenv environment variable files
13+
.env
14+
.env.*
15+
!.env.example
16+
17+
# caches
18+
.cache
19+
*.tsbuildinfo
20+
21+
# Finder (MacOS) folder config
22+
.DS_Store

templates/react/AGENTS.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
description: Use Bun instead of Node.js, npm, pnpm, or vite.
3+
globs: "*.ts, *.tsx, *.html, *.css, *.js, *.jsx, package.json"
4+
alwaysApply: false
5+
---
6+
7+
Default to using Bun instead of Node.js.
8+
9+
- Use `bun <file>` instead of `node <file>` or `ts-node <file>`
10+
- Use `bun test` instead of `jest` or `vitest`
11+
- Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
12+
- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
13+
- Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
14+
- Use `bunx <package> <command>` instead of `npx <package> <command>`
15+
- Bun automatically loads .env, so don't use dotenv.
16+
17+
## APIs
18+
19+
- `Bun.serve()` supports WebSockets, HTTPS, and routes. Don't use `express`.
20+
- `bun:sqlite` for SQLite. Don't use `better-sqlite3`.
21+
- `Bun.redis` for Redis. Don't use `ioredis`.
22+
- `Bun.sql` for Postgres. Don't use `pg` or `postgres.js`.
23+
- `WebSocket` is built-in. Don't use `ws`.
24+
- Prefer `Bun.file` over `node:fs`'s readFile/writeFile
25+
- Bun.$`ls` instead of execa.
26+
27+
## Testing
28+
29+
Use `bun test` to run tests.
30+
31+
```ts#index.test.ts
32+
import { test, expect } from "bun:test";
33+
34+
test("hello world", () => {
35+
expect(1).toBe(1);
36+
});
37+
```
38+
39+
## Frontend
40+
41+
Use HTML imports with `Bun.serve()`. Don't use `vite`. HTML imports fully support React, CSS, Tailwind.
42+
43+
Server:
44+
45+
```ts#index.ts
46+
import index from "./index.html"
47+
48+
Bun.serve({
49+
routes: {
50+
"/": index,
51+
"/api/users/:id": {
52+
GET: (req) => {
53+
return new Response(JSON.stringify({ id: req.params.id }));
54+
},
55+
},
56+
},
57+
// optional websocket support
58+
websocket: {
59+
open: (ws) => {
60+
ws.send("Hello, world!");
61+
},
62+
message: (ws, message) => {
63+
ws.send(message);
64+
},
65+
close: (ws) => {
66+
// handle close
67+
}
68+
},
69+
development: {
70+
hmr: true,
71+
console: true,
72+
}
73+
})
74+
```
75+
76+
HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. `<link>` tags can point to stylesheets and Bun's CSS bundler will bundle.
77+
78+
```html#index.html
79+
<html>
80+
<body>
81+
<h1>Hello, world!</h1>
82+
<script type="module" src="./frontend.tsx"></script>
83+
</body>
84+
</html>
85+
```
86+
87+
With the following `frontend.tsx`:
88+
89+
```tsx#frontend.tsx
90+
import React from "react";
91+
import { createRoot } from "react-dom/client";
92+
93+
// import .css files directly and it works
94+
import './index.css';
95+
96+
const root = createRoot(document.body);
97+
98+
export default function Frontend() {
99+
return <h1>Hello, world!</h1>;
100+
}
101+
102+
root.render(<Frontend />);
103+
```
104+
105+
Then, run index.ts
106+
107+
```sh
108+
bun --hot ./index.ts
109+
```
110+
111+
For more information, read the Bun API docs in `node_modules/bun-types/docs/**.mdx`.

templates/react/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Create Rubric App
2+
3+
This project is bootstrapped with [`create-rubric-app`](https://github.com/RubricLab/create-rubric-app).
4+
5+
## Getting Started
6+
7+
### Option 1: Docker (recommended)
8+
9+
The easiest way to run the full stack (app + Postgres + Redis):
10+
11+
```sh
12+
# Create a .env file with your API keys
13+
cp .env.example .env
14+
15+
# Start all services
16+
docker compose up
17+
```
18+
19+
Open [localhost:3000](http://localhost:3000) in your browser.
20+
21+
### Option 2: Local development
22+
23+
#### 1. Install dependencies
24+
25+
```sh
26+
bun i
27+
```
28+
29+
#### 2. Set up environment
30+
31+
Create a `.env` file with:
32+
33+
```sh
34+
DATABASE_URL=postgres://postgres:postgres@localhost:5432/app
35+
REDIS_URL=redis://localhost:6379
36+
GITHUB_CLIENT_ID=your_github_client_id
37+
GITHUB_CLIENT_SECRET=your_github_client_secret
38+
OPENAI_API_KEY=your_openai_api_key
39+
PUBLIC_AUTH_URL=http://localhost:3000
40+
```
41+
42+
#### 3. Start Postgres & Redis
43+
44+
```sh
45+
docker compose up postgres redis
46+
```
47+
48+
#### 4. Run the development server
49+
50+
```sh
51+
bun dev
52+
```
53+
54+
Open [localhost:3000](http://localhost:3000) in your browser.
55+
56+
## Deployment
57+
58+
To serve your app to users, deploy to any container platform using the provided Docker setup.
59+
60+
## Learn More
61+
62+
To learn more about this project, take a look at this [blog post](https://rubriclabs.com/blog/create-rubric-app).

templates/react/biome.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["@rubriclab/config/biome"]
3+
}

0 commit comments

Comments
 (0)