blumenjs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -0
- package/dist/cli/blumen.js +697 -0
- package/dist/cli/commands/build.js +85 -0
- package/dist/cli/commands/create.js +384 -0
- package/dist/cli/commands/dev.js +163 -0
- package/dist/cli/commands/start.js +129 -0
- package/dist/cli/utils.js +85 -0
- package/dist/templates/app/client/entry.tsx +41 -0
- package/dist/templates/app/pages/BlumenStarter.tsx +398 -0
- package/dist/templates/app/pages/NotFound.tsx +22 -0
- package/dist/templates/app/shared/DefaultApp.tsx +5 -0
- package/dist/templates/app/shared/DefaultDocument.tsx +76 -0
- package/dist/templates/app/shared/Link.tsx +73 -0
- package/dist/templates/app/shared/RouterContext.tsx +176 -0
- package/dist/templates/app/shared/router.ts +23 -0
- package/dist/templates/go-server/main.go +175 -0
- package/dist/templates/node-ssr/server.ts +141 -0
- package/dist/templates/scripts/generate-routes.ts +220 -0
- package/package.json +77 -0
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# SSR Go + React
|
|
2
|
+
|
|
3
|
+
A minimal, production-quality SSR engine built with Go and React. The Go server handles HTTP routing and serves as the entry point, while a Node.js service renders React components to HTML.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Browser → Go Server (:3000) → Node SSR (:4000) → React → HTML
|
|
9
|
+
↓
|
|
10
|
+
Static JS bundle → Hydration
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- **Go Server** — Routing, SSR orchestration, static files
|
|
14
|
+
- **Node SSR Service** — React `renderToString` via HTTP API
|
|
15
|
+
- **React App** — Isomorphic pages (Home, About)
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
### Prerequisites
|
|
20
|
+
|
|
21
|
+
- Go 1.21+
|
|
22
|
+
- Node.js 18+
|
|
23
|
+
- npm or yarn
|
|
24
|
+
|
|
25
|
+
### Install Dependencies
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Build Client Bundle
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm run build:client
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Start Both Servers
|
|
38
|
+
|
|
39
|
+
Terminal 1 — Node SSR Service:
|
|
40
|
+
```bash
|
|
41
|
+
npm run dev:ssr
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Terminal 2 — Go Server:
|
|
45
|
+
```bash
|
|
46
|
+
npm run dev:go
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or use the convenience command (requires `concurrently`):
|
|
50
|
+
```bash
|
|
51
|
+
npm run dev
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Visit the App
|
|
55
|
+
|
|
56
|
+
Open http://localhost:3000
|
|
57
|
+
|
|
58
|
+
## Development
|
|
59
|
+
|
|
60
|
+
### Project Structure
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
.
|
|
64
|
+
├── go-server/
|
|
65
|
+
│ └── main.go # Go HTTP server, SSR proxy
|
|
66
|
+
├── node-ssr/
|
|
67
|
+
│ └── server.ts # Node SSR service (renderToString endpoint)
|
|
68
|
+
├── app/
|
|
69
|
+
│ ├── pages/
|
|
70
|
+
│ │ ├── Home.tsx # Home page component
|
|
71
|
+
│ │ └── About.tsx # About page component
|
|
72
|
+
│ └── client/
|
|
73
|
+
│ └── entry.tsx # Client hydration entry point
|
|
74
|
+
├── templates/
|
|
75
|
+
│ └── index.html # HTML template (Go html/template)
|
|
76
|
+
├── static/
|
|
77
|
+
│ └── js/
|
|
78
|
+
│ └── bundle.js # Compiled client bundle (generated)
|
|
79
|
+
├── package.json
|
|
80
|
+
├── tsconfig.json
|
|
81
|
+
└── webpack.config.js
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Request Flow
|
|
85
|
+
|
|
86
|
+
1. Browser requests `GET /`
|
|
87
|
+
2. Go server prepares SSR request with path, query, params
|
|
88
|
+
3. Go POSTs JSON to Node SSR service at `:4000/render`
|
|
89
|
+
4. Node renders the React page component to HTML string
|
|
90
|
+
5. Go injects HTML + serialized props into template
|
|
91
|
+
6. Browser receives full HTML, client bundle hydrates React
|
|
92
|
+
|
|
93
|
+
## Production Build
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npm run build
|
|
97
|
+
npm start
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## API
|
|
101
|
+
|
|
102
|
+
### POST /render (Node SSR)
|
|
103
|
+
|
|
104
|
+
Request:
|
|
105
|
+
```json
|
|
106
|
+
{
|
|
107
|
+
"path": "/about",
|
|
108
|
+
"query": {},
|
|
109
|
+
"params": {}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Response:
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"html": "<div class=\"about-page\">...</div>",
|
|
117
|
+
"props": { "serverRendered": true, "timestamp": 1234567890 }
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Future Roadmap
|
|
122
|
+
|
|
123
|
+
- File-based routing
|
|
124
|
+
- API routes
|
|
125
|
+
- CLI tooling
|
|
126
|
+
- Hot reload in development
|
|
127
|
+
- Production build optimization
|