Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ Python 包统一通过 `uv pip install` 安装和升级。已有 CLI 时复用
| `farfarfun-web` | farfarfun 组织官网,单个 npm 包 `farfarfun-web`(8800) |
| `funfluid` | funfluid 前后端(18806 / 8806) |
| `funlesson` | funlesson 前后端(18814 / 8814) |
| `courseware` | 交互课程平台,API + 同步 Worker + 前端(8008 / 8817);安装 `courseware-api` 与 `@farfarfun/courseware-web` |
| `fungame` | fungame 后端 + 管理端 + 用户端(8809 / 8807 / 8808);后端包为 `fungame-api`,前端包为 `@farfarfun/fungame-admin`、`@farfarfun/fungame-web` |
| `funflix` | funflix 前后端(18810 / 8810) |
| `funread` | funread 前后端(18811 / 8811) |
Expand All @@ -168,6 +169,10 @@ Python 包统一通过 `uv pip install` 安装和升级。已有 CLI 时复用
| `casdoor` | Casdoor SSO(8805),官方二进制 + SQLite |

Casdoor 的 Caddy、登录方式和 OIDC 接入说明见 [docs/casdoor.md](docs/casdoor.md)。

Courseware 使用团队的 funpy / `@farfarfun` npm 源,安装前需配置源及读取权限。首次安装后运行 `courseware-api init` 生成 `~/.farfarfun/courseware/backend/config.json`,配置 PostgreSQL 连接后再次运行 `courseware-api init` 完成迁移,再运行 `courseware-api create-admin admin` 创建管理员。随后执行 `fundeploy service courseware start`;API 的生命周期命令同时管理课程同步 Worker。前端配置位于 `~/.farfarfun/courseware/frontend/config.json`,由 CLI 首次启动生成。`CW_CONFIG_FILE` / `CW_WEB_CONFIG_FILE` 可覆盖配置路径。

Courseware 默认前端端口为 8817,避免与 funlesson 的 8814 冲突;已有 8814/frpc 入口可设置 `COURSEWARE_FRONTEND_PORT=8814`(并同步后端 `CW_PUBLIC_ORIGIN`)。`COURSEWARE_BACKEND_PORT` 会自动传入前端代理目标。frpc 只需转发前端端口,后端来源配置填写实际公网入口。升级前备份数据库和课程文件;数据库迁移需显式运行 `courseware-api init`,`rollback` 只回退软件包,不自动回退数据结构。
新服务的目录与配置约定见 [开发规范](docs/development.md)。

除 Casdoor 外,服务默认只监听回环地址。Casdoor 上游会绑定所有网卡,启动前必须
Expand Down
93 changes: 92 additions & 1 deletion src/service/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn all() -> Vec<Box<dyn Service>> {
upstream::declared(farfarfun_web()),
upstream::declared(funfluid_web()),
upstream::declared(funlesson_web()),
upstream::declared(courseware()),
upstream::declared(fungame_web()),
upstream::declared(funflix_web()),
upstream::boxed(funread_web()),
Expand Down Expand Up @@ -168,6 +169,42 @@ fn funlesson_web() -> ServiceSpec {
ServiceSpec::new("funlesson", "funlesson 前后端", vec![backend, frontend]).entry("frontend")
}

// ---------------------------------------------------------------- courseware

fn courseware() -> ServiceSpec {
// API 的 server 命令同时管理同步 Worker;Worker 没有单独的网络端口。
let backend = Component::new(
"backend",
"后端 courseware-api(含 Worker)",
Pkg::pip(
&env_str("COURSEWARE_BACKEND_PACKAGE", "courseware-api"),
"courseware-api",
),
&env_str("COURSEWARE_BACKEND_HOST", "127.0.0.1"),
env_port("COURSEWARE_BACKEND_PORT", 8008),
)
.version(env_opt("COURSEWARE_BACKEND_VERSION"))
.cli_shape(server_subcommand_shape(vec![]));
let frontend = Component::new(
"frontend",
"前端 courseware-web",
Pkg::npm(
&env_str("COURSEWARE_FRONTEND_PACKAGE", "@farfarfun/courseware-web"),
"courseware-web",
),
&env_str("COURSEWARE_FRONTEND_HOST", "127.0.0.1"),
env_port("COURSEWARE_FRONTEND_PORT", 8817),
)
.version(env_opt("COURSEWARE_FRONTEND_VERSION"))
.cli_shape(server_subcommand_shape(args![
"--backend",
Arg::SiblingUrl("backend".into())
]));
ServiceSpec::new("courseware", "交互课程平台", vec![backend, frontend])
.entry("frontend")
.note("首次安装:courseware-api init,配置 PostgreSQL 后再次 init,再创建管理员。前端默认 8817;已有 8814/frpc 入口用 COURSEWARE_FRONTEND_PORT=8814 保持不变,并同步 CW_PUBLIC_ORIGIN。")
}

// ---------------------------------------------------------------- fungame-web

fn fungame_web() -> ServiceSpec {
Expand Down Expand Up @@ -974,6 +1011,52 @@ mod tests {
);
}

#[test]
fn courseware_前端代理到_api_且_api_拥有_worker() {
let _排队 = 排队();
let spec = courseware();
assert_eq!(spec.components.len(), 2);
assert_eq!(
argv(&spec, "backend", |c| &c.start),
[
"courseware-api",
"server",
"start",
"--host",
"127.0.0.1",
"--port",
"8008"
]
);
assert_eq!(
argv(&spec, "frontend", |c| &c.start),
[
"courseware-web",
"server",
"start",
"--host",
"127.0.0.1",
"--port",
"8817",
"--backend",
"http://127.0.0.1:8008"
]
);
assert_eq!(
argv(&spec, "backend", |c| &c.stop),
["courseware-api", "server", "stop"]
);
assert_eq!(
spec.component("frontend").unwrap().pkg.name(),
"@farfarfun/courseware-web"
);
std::env::set_var("COURSEWARE_BACKEND_PORT", "28008");
let overridden = courseware();
assert!(argv(&overridden, "frontend", |c| &c.start)
.contains(&"http://127.0.0.1:28008".to_string()));
std::env::remove_var("COURSEWARE_BACKEND_PORT");
}

#[test]
fn fungame_的两个前端都指向同一个后端() {
let _排队 = 排队();
Expand Down Expand Up @@ -1006,7 +1089,14 @@ mod tests {
#[test]
fn 前后端整套服务使用产品名() {
let names = names();
for name in ["funfluid", "funlesson", "fungame", "funflix", "funread"] {
for name in [
"funfluid",
"funlesson",
"courseware",
"fungame",
"funflix",
"funread",
] {
assert!(names.contains(&name.to_string()), "缺少服务 {name}");
assert!(
!names.contains(&format!("{name}-web")),
Expand Down Expand Up @@ -1052,6 +1142,7 @@ mod tests {
farfarfun_web(),
funfluid_web(),
funlesson_web(),
courseware(),
fungame_web(),
funflix_web(),
funread_web().spec,
Expand Down
Loading