diff --git a/demo/app/node-frontend-react-class/.dockerignore b/demo/app/node-frontend-react-class/.dockerignore
new file mode 100644
index 0000000..89fe1f0
--- /dev/null
+++ b/demo/app/node-frontend-react-class/.dockerignore
@@ -0,0 +1,4 @@
+dist/
+node_modules/
+.git/
+.DS_Store
diff --git a/demo/app/node-frontend-react-class/.gitignore b/demo/app/node-frontend-react-class/.gitignore
new file mode 100644
index 0000000..1061ea7
--- /dev/null
+++ b/demo/app/node-frontend-react-class/.gitignore
@@ -0,0 +1,3 @@
+dist/
+node_modules/
+npm-debug.log*
diff --git a/demo/app/node-frontend-react-class/Dockerfile b/demo/app/node-frontend-react-class/Dockerfile
new file mode 100644
index 0000000..b4e9802
--- /dev/null
+++ b/demo/app/node-frontend-react-class/Dockerfile
@@ -0,0 +1,23 @@
+# 编译阶段:compile-node22(Vite 7 需要 Node >= 20.19)
+FROM registry.cn-shanghai.aliyuncs.com/odboy/kenaito:compile-node22 AS build
+WORKDIR /src
+
+COPY package.json package-lock.json* ./
+# npm 源由镜像的 /usr/local/node/etc/npmrc 指向 npmmirror,无需额外换源
+RUN npm install --no-audit --no-fund
+
+COPY . ./
+RUN npm run build && ls -lh dist/ dist/assets/
+
+# 运行阶段:Tengine 3.1.0(自建 proxy-tengine3 镜像)托管静态文件
+FROM registry.cn-shanghai.aliyuncs.com/odboy/kenaito:proxy-tengine3 AS runtime
+LABEL MAINTAINER="tianjun@odboy.cn"
+ENV TimeZone=Asia/Shanghai
+# 站点配置与构建产物都放进镜像:conf.d/*.conf 由主配置 include,html/ 为站点根目录
+COPY nginx/node-frontend-react-class.conf /usr/local/nginx/conf/conf.d/node-frontend-react-class.conf
+COPY --from=build /src/dist/ /usr/local/nginx/html/
+# 构建期自检:配置语法错误直接让镜像构建失败;纯静态站点没有上游主机名,nginx -t 可直接通过
+RUN /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
+EXPOSE 80
+STOPSIGNAL SIGQUIT
+CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]
diff --git a/demo/app/node-frontend-react-class/README.md b/demo/app/node-frontend-react-class/README.md
new file mode 100644
index 0000000..f4c5881
--- /dev/null
+++ b/demo/app/node-frontend-react-class/README.md
@@ -0,0 +1,72 @@
+# node-frontend-react-class 示例
+
+React 19 **类组件**(class component)写法的前端项目,**构建阶段**用 `compile-node22` 跑 Vite,**运行阶段**以自建
+`proxy-tengine3` 镜像为基座托管静态文件。函数组件 + Hooks 写法见同级的
+[`node-frontend-react-function`](../node-frontend-react-function/README.md),两者页面与部署方式完全一致,只差组件写法。
+
+| 阶段 | 镜像 | 说明 |
+| --- | --- | --- |
+| 编译 | `registry.cn-shanghai.aliyuncs.com/odboy/kenaito:compile-node22` | Node 22 + npm(源为 npmmirror),Vite 7 要求 Node ≥ 20.19 |
+| 运行 | `registry.cn-shanghai.aliyuncs.com/odboy/kenaito:proxy-tengine3` | Tengine 3.1.0,托管 `dist/` |
+
+纯前端项目:页面数据全部在浏览器内产生,不调用任何后端接口,部署只需要一个 Tengine 容器。
+
+### 示例内容
+
+```
+node-frontend-react-class/
+├── package.json # react 19.3.1 / react-dom 19.3.1;vite 7 + plugin-react 5
+├── vite.config.js # base: './';react/react-dom 单独拆包
+├── index.html
+├── src/
+│ ├── main.jsx # createRoot + StrictMode
+│ ├── App.jsx # class App extends Component,this.state 切换页签
+│ ├── styles.css # 轻量手写样式,不引 UI 库
+│ └── views/
+│ ├── Home.jsx # this.state + componentDidMount/WillUnmount:计数器、时钟、受控输入
+│ ├── Form.jsx # 类组件受控表单 + validate,错误/结果放 this.state
+│ └── About.jsx # 版本与部署说明(无状态类组件)
+├── nginx/
+│ └── node-frontend-react-class.conf # Tengine 站点配置:静态托管 + /healthz
+├── Dockerfile # 两阶段:compile-node22 -> proxy-tengine3
+├── build.sh # 构建镜像(PUSH=1 时同时推送)
+├── docker-compose.yml # 只部署前端(端口 8093)
+├── startup.sh / shutdown.sh
+└── .dockerignore / .gitignore
+```
+
+### 构建与部署
+
+```shell
+sh build.sh # docker build -t registry.cn-shanghai.aliyuncs.com/odboy/kenaito:demo-node-frontend-react-class .
+PUSH=1 sh build.sh # 构建并推送
+sh startup.sh # docker-compose -f docker-compose.yml -p node-frontend-react-class-demo up -d
+```
+
+访问 http://127.0.0.1:8093/ ;`curl http://127.0.0.1:8093/healthz` 返回 `ok`。
+
+### 本地开发(不用 docker)
+
+```shell
+npm install
+npm run dev # http://127.0.0.1:5573
+```
+
+### 关键点
+
+**类组件写法**:组件继承 `Component`,状态放 `this.state`、更新用 `this.setState`;定时器在
+`componentDidMount` 里创建、`componentWillUnmount` 里清理(对应函数版的 `useEffect` cleanup)。
+事件处理函数在构造函数里 `bind(this)`,或用箭头函数保持 `this`。
+
+**函数版 vs 类版**:这是官方文档并列的两种写法,行为等价。新代码建议用函数组件 + Hooks
+(见 `node-frontend-react-function`);类组件在旧项目、错误边界(`componentDidCatch`)里仍会遇到。
+
+**站点配置**:配置放在 `nginx/node-frontend-react-class.conf`,构建时 `COPY` 到 `/usr/local/nginx/conf/conf.d/`
+(镜像自带 nginx.conf 已经 `include conf.d/*.conf`);compose 又把宿主机 `./nginx` 挂到同一个 `conf.d`。
+挂目录而不是单文件:单文件挂载编辑会换 inode,容器内看不到改动。
+
+### 停止
+
+```shell
+sh shutdown.sh
+```
diff --git a/demo/app/node-frontend-react-class/build.sh b/demo/app/node-frontend-react-class/build.sh
new file mode 100755
index 0000000..538e4f9
--- /dev/null
+++ b/demo/app/node-frontend-react-class/build.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+# 在示例目录下构建示例镜像(编译 + 运行两阶段均在本机 docker 内完成)
+set -euo pipefail
+cd "$(dirname "$0")"
+
+IMAGE=${IMAGE:-registry.cn-shanghai.aliyuncs.com/odboy/kenaito:demo-node-frontend-react-class}
+docker build -t "${IMAGE}" .
+
+if [ "${PUSH:-0}" = "1" ]; then
+ docker push "${IMAGE}"
+fi
diff --git a/demo/app/node-frontend-react-class/docker-compose.yml b/demo/app/node-frontend-react-class/docker-compose.yml
new file mode 100644
index 0000000..9483259
--- /dev/null
+++ b/demo/app/node-frontend-react-class/docker-compose.yml
@@ -0,0 +1,32 @@
+version: '3.8'
+
+# 网段避开其它示例(172.31.0/24 ~ 172.31.6/24 已被 go / rust / node-backend / vue2 / vue3 / react-function / vite5 占用)
+networks:
+ node-frontend-react-class-demo:
+ ipam:
+ driver: default
+ config:
+ - subnet: "172.31.7.0/24"
+
+services:
+ frontend:
+ image: registry.cn-shanghai.aliyuncs.com/odboy/kenaito:demo-node-frontend-react-class # 镜像由 build.sh 构建
+ container_name: node-frontend-react-class-demo
+ restart: unless-stopped
+ ports: # 映射端口:前端页面
+ - "8093:80"
+ volumes: # 只挂载站点配置目录,改完 reload 即可,不必重建镜像
+ # 挂目录而不是单文件:单文件挂载在宿主机上编辑会换 inode,容器内看不到改动
+ - "./nginx:/usr/local/nginx/conf/conf.d"
+ environment: # 设置环境变量,相当于docker run命令中的-e
+ TZ: Asia/Shanghai
+ healthcheck:
+ # 运行镜像自带 net-tools,直接用端口探测
+ test: ["CMD-SHELL", "netstat -tln | grep -q ':80 '"]
+ interval: 30s
+ timeout: 5s
+ retries: 3
+ start_period: 5s
+ networks:
+ node-frontend-react-class-demo:
+ ipv4_address: 172.31.7.20
diff --git a/demo/app/node-frontend-react-class/index.html b/demo/app/node-frontend-react-class/index.html
new file mode 100644
index 0000000..a677600
--- /dev/null
+++ b/demo/app/node-frontend-react-class/index.html
@@ -0,0 +1,12 @@
+
+
+
+
+
+ node-frontend-react-class | React 19 类组件
+
+
+
+
+
+
diff --git a/demo/app/node-frontend-react-class/nginx/node-frontend-react-class.conf b/demo/app/node-frontend-react-class/nginx/node-frontend-react-class.conf
new file mode 100644
index 0000000..9081d01
--- /dev/null
+++ b/demo/app/node-frontend-react-class/nginx/node-frontend-react-class.conf
@@ -0,0 +1,29 @@
+# node-frontend-react-class 站点:Tengine 3.1.0 托管 React 构建产物(纯静态,无后端依赖)
+server {
+ listen 80;
+ server_name _;
+
+ access_log /dev/stdout main;
+
+ root /usr/local/nginx/html;
+ index index.html;
+
+ # 静态资源带 hash,长缓存;index.html 每次重新验证,保证发版后立即生效
+ location /assets/ {
+ expires 30d;
+ add_header Cache-Control "public, immutable";
+ try_files $uri =404;
+ }
+
+ # 前端路由兜底:示例不引入路由库,保留是为了以后加 react-router 时不用改配置
+ location / {
+ try_files $uri $uri/ /index.html;
+ }
+
+ # 健康检查:直接读 index.html
+ location = /healthz {
+ access_log off;
+ default_type text/plain;
+ return 200 "ok\n";
+ }
+}
diff --git a/demo/app/node-frontend-react-class/package.json b/demo/app/node-frontend-react-class/package.json
new file mode 100644
index 0000000..654d565
--- /dev/null
+++ b/demo/app/node-frontend-react-class/package.json
@@ -0,0 +1,23 @@
+{
+ "name": "node-frontend-react-class",
+ "version": "1.0.0",
+ "private": true,
+ "description": "React 19 前端示例,构建产物由 Tengine 托管",
+ "type": "module",
+ "engines": {
+ "node": ">=20.19"
+ },
+ "scripts": {
+ "dev": "vite",
+ "build": "vite build",
+ "preview": "vite preview --port 4173"
+ },
+ "dependencies": {
+ "react": "19.3.1",
+ "react-dom": "19.3.1"
+ },
+ "devDependencies": {
+ "@vitejs/plugin-react": "5.2.0",
+ "vite": "7.3.8"
+ }
+}
diff --git a/demo/app/node-frontend-react-class/shutdown.sh b/demo/app/node-frontend-react-class/shutdown.sh
new file mode 100755
index 0000000..38ac654
--- /dev/null
+++ b/demo/app/node-frontend-react-class/shutdown.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+set -euo pipefail
+cd "$(dirname "$0")"
+docker-compose -f docker-compose.yml -p node-frontend-react-class-demo down
diff --git a/demo/app/node-frontend-react-class/src/App.jsx b/demo/app/node-frontend-react-class/src/App.jsx
new file mode 100644
index 0000000..b80e8ab
--- /dev/null
+++ b/demo/app/node-frontend-react-class/src/App.jsx
@@ -0,0 +1,51 @@
+import { Component } from 'react';
+import Home from './views/Home.jsx';
+import Form from './views/Form.jsx';
+import About from './views/About.jsx';
+
+const TABS = [
+ { key: 'home', label: '首页', view: Home },
+ { key: 'form', label: '表单', view: Form },
+ { key: 'about', label: '关于', view: About },
+];
+
+// 类组件写法:用 this.state + this.setState 管理页签,等价于函数版的 useState
+export default class App extends Component {
+ constructor(props) {
+ super(props);
+ this.state = { active: 'home' };
+ this.setActive = this.setActive.bind(this);
+ }
+
+ setActive(key) {
+ this.setState({ active: key });
+ }
+
+ render() {
+ const { active } = this.state;
+ const Current = TABS.find((t) => t.key === active).view;
+
+ return (
+
+
+ node-frontend-react-class
+
+
+
+
+
+
+ );
+ }
+}
diff --git a/demo/app/node-frontend-react-class/src/main.jsx b/demo/app/node-frontend-react-class/src/main.jsx
new file mode 100644
index 0000000..f2baba2
--- /dev/null
+++ b/demo/app/node-frontend-react-class/src/main.jsx
@@ -0,0 +1,10 @@
+import { StrictMode } from 'react';
+import { createRoot } from 'react-dom/client';
+import App from './App.jsx';
+import './styles.css';
+
+createRoot(document.getElementById('root')).render(
+
+
+ ,
+);
diff --git a/demo/app/node-frontend-react-class/src/styles.css b/demo/app/node-frontend-react-class/src/styles.css
new file mode 100644
index 0000000..df45f35
--- /dev/null
+++ b/demo/app/node-frontend-react-class/src/styles.css
@@ -0,0 +1,156 @@
+* {
+ box-sizing: border-box;
+}
+
+html,
+body,
+#root {
+ height: 100%;
+ margin: 0;
+}
+
+body {
+ font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
+ color: #303133;
+ background: #f5f7fa;
+}
+
+.header {
+ display: flex;
+ align-items: center;
+ gap: 24px;
+ height: 56px;
+ padding: 0 20px;
+ background: #fff;
+ border-bottom: 1px solid #ebeef5;
+}
+
+.logo {
+ font-size: 18px;
+ font-weight: 600;
+ color: #409eff;
+}
+
+.nav {
+ display: flex;
+ gap: 8px;
+}
+
+.nav-item {
+ padding: 6px 14px;
+ border: 1px solid transparent;
+ border-radius: 4px;
+ background: transparent;
+ color: #303133;
+ cursor: pointer;
+}
+
+.nav-item:hover {
+ color: #409eff;
+}
+
+.nav-item.active {
+ color: #409eff;
+ border-color: #d9ecff;
+ background: #ecf5ff;
+}
+
+.main {
+ padding: 20px;
+}
+
+.card {
+ background: #fff;
+ border: 1px solid #ebeef5;
+ border-radius: 4px;
+ padding: 20px;
+}
+
+.card + .card {
+ margin-top: 16px;
+}
+
+.card-title {
+ margin: 0 0 16px;
+ font-size: 16px;
+ font-weight: 600;
+}
+
+.grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
+ gap: 16px;
+}
+
+.kv {
+ width: 100%;
+ border-collapse: collapse;
+}
+
+.kv th,
+.kv td {
+ padding: 6px 12px;
+ border: 1px solid #ebeef5;
+ text-align: left;
+}
+
+.kv th {
+ width: 40%;
+ background: #fafafa;
+}
+
+.clock {
+ margin: 0 0 12px;
+ font-size: 24px;
+ font-weight: 600;
+ font-variant-numeric: tabular-nums;
+}
+
+.btn {
+ padding: 6px 14px;
+ border: 1px solid #dcdfe6;
+ border-radius: 4px;
+ background: #fff;
+ cursor: pointer;
+}
+
+.btn.primary {
+ color: #fff;
+ border-color: #409eff;
+ background: #409eff;
+}
+
+.field {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ margin-bottom: 14px;
+}
+
+.field label {
+ width: 80px;
+ text-align: right;
+}
+
+.field input,
+.field select {
+ flex: 1;
+ max-width: 320px;
+ padding: 6px 10px;
+ border: 1px solid #dcdfe6;
+ border-radius: 4px;
+}
+
+.hint {
+ margin-top: 12px;
+ padding: 8px 12px;
+ border-radius: 4px;
+ background: #f0f9eb;
+ color: #67c23a;
+}
+
+.error {
+ margin-left: 8px;
+ color: #f56c6c;
+ font-size: 12px;
+}
diff --git a/demo/app/node-frontend-react-class/src/views/About.jsx b/demo/app/node-frontend-react-class/src/views/About.jsx
new file mode 100644
index 0000000..601500f
--- /dev/null
+++ b/demo/app/node-frontend-react-class/src/views/About.jsx
@@ -0,0 +1,20 @@
+import { Component } from 'react';
+
+// 静态说明页:类组件写法,无状态
+export default class About extends Component {
+ render() {
+ return (
+
+
关于
+
+
+ | 框架 | React 19.3.1(class 组件) |
+ | 写法 | 继承 Component,状态在 this.state,生命周期用 componentDidMount/WillUnmount |
+ | 构建 | Vite 7 + @vitejs/plugin-react 5 |
+ | 部署 | Tengine 3.1.0(proxy-tengine3 镜像)托管 dist/ |
+
+
+
+ );
+ }
+}
diff --git a/demo/app/node-frontend-react-class/src/views/Form.jsx b/demo/app/node-frontend-react-class/src/views/Form.jsx
new file mode 100644
index 0000000..8b1ba8e
--- /dev/null
+++ b/demo/app/node-frontend-react-class/src/views/Form.jsx
@@ -0,0 +1,76 @@
+import { Component } from 'react';
+
+const EMPTY = { name: '', type: '', enabled: true, date: '' };
+
+// 类组件受控表单:字段统一走 this.state.form,错误与结果各占一个 state 字段
+export default class Form extends Component {
+ constructor(props) {
+ super(props);
+ this.state = { form: { ...EMPTY }, errors: {}, result: '' };
+ this.update = this.update.bind(this);
+ this.submit = this.submit.bind(this);
+ this.reset = this.reset.bind(this);
+ }
+
+ update(key, value) {
+ this.setState((s) => ({ form: { ...s.form, [key]: value } }));
+ }
+
+ validate(form) {
+ const next = {};
+ if (!form.name.trim()) next.name = '请输入名称';
+ if (!form.type) next.type = '请选择类型';
+ this.setState({ errors: next });
+ return Object.keys(next).length === 0;
+ }
+
+ submit(e) {
+ e.preventDefault();
+ const { form } = this.state;
+ if (!this.validate(form)) return;
+ this.setState({ result: `已提交:${JSON.stringify(form)}` });
+ }
+
+ reset() {
+ this.setState({ form: { ...EMPTY }, errors: {}, result: '' });
+ }
+
+ render() {
+ const { form, errors, result } = this.state;
+ return (
+
+
React 类组件受控表单
+
+ {result &&
{result}
}
+
+ );
+ }
+}
diff --git a/demo/app/node-frontend-react-class/src/views/Home.jsx b/demo/app/node-frontend-react-class/src/views/Home.jsx
new file mode 100644
index 0000000..ee2e9f6
--- /dev/null
+++ b/demo/app/node-frontend-react-class/src/views/Home.jsx
@@ -0,0 +1,78 @@
+import { Component, version as reactVersion } from 'react';
+
+function format(d) {
+ const p = (n) => String(n).padStart(2, '0');
+ return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
+}
+
+// 类组件:状态放 this.state,用 componentDidMount / componentWillUnmount 管理定时器
+export default class Home extends Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ count: 0,
+ clock: format(new Date()),
+ keyword: '',
+ };
+ this.timer = null;
+ }
+
+ componentDidMount() {
+ this.timer = setInterval(() => {
+ this.setState({ clock: format(new Date()) });
+ }, 1000);
+ }
+
+ componentWillUnmount() {
+ clearInterval(this.timer);
+ this.timer = null;
+ }
+
+ render() {
+ const { count, clock, keyword } = this.state;
+ return (
+ <>
+
+
+
运行时
+
+
+ | React | {reactVersion} |
+ | 写法 | class(继承 Component) |
+ | 路由 | 示例用 this.state 页签,不引入路由库 |
+
+
+
+
+
+
计数器(this.state)
+
{count}
+
{' '}
+
{' '}
+
+
+
+
+
当前时间(componentDidMount)
+
{clock}
+
前端本地时间,不请求后端
+
+
+
+
+
受控输入
+
+
+ this.setState({ keyword: e.target.value })}
+ placeholder="输入关键字过滤,纯前端"
+ />
+
+ {keyword &&
已输入:{keyword}
}
+
+ >
+ );
+ }
+}
diff --git a/demo/app/node-frontend-react-class/startup.sh b/demo/app/node-frontend-react-class/startup.sh
new file mode 100755
index 0000000..0ed40b2
--- /dev/null
+++ b/demo/app/node-frontend-react-class/startup.sh
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+set -euo pipefail
+cd "$(dirname "$0")"
+docker-compose -f docker-compose.yml -p node-frontend-react-class-demo up -d
+docker-compose -f docker-compose.yml -p node-frontend-react-class-demo ps
diff --git a/demo/app/node-frontend-react-class/vite.config.js b/demo/app/node-frontend-react-class/vite.config.js
new file mode 100644
index 0000000..c7d6635
--- /dev/null
+++ b/demo/app/node-frontend-react-class/vite.config.js
@@ -0,0 +1,23 @@
+import { defineConfig } from 'vite';
+import react from '@vitejs/plugin-react';
+
+// 纯静态前端:产物由 Tengine 托管,base 用相对路径,部署到任意子路径都能跑
+export default defineConfig({
+ plugins: [react()],
+ base: './',
+ server: {
+ host: '0.0.0.0',
+ port: 5573,
+ },
+ build: {
+ outDir: 'dist',
+ sourcemap: false,
+ rollupOptions: {
+ output: {
+ manualChunks: {
+ react: ['react', 'react-dom'],
+ },
+ },
+ },
+ },
+});