ACCEPT REQUEST

docs: add build-from-source guide, optional SERVER_PORT config
This commit is contained in:
Furrium Network authored and GitHub committed 2026-08-09 16:34:25 +08:00
commit d986ecdbc4
5 files changed
+1951 -1

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
node_modules/
uploads/
*.log
.DS_Store
.env
+72
View File
@@ -19,3 +19,75 @@
git clone https://github.com/furrium/forumlify.git
cd forumlify
docker-compose up -d
```
应用默认运行在 `http://localhost:3003`。
### 从源码构建
> 适合二次开发、自定义部署或不想用 Docker 的场景。
#### 环境要求
- Node.js 18+
- PostgreSQL 13+(`schema.sql` 使用了内置的 `gen_random_uuid()`)
#### 步骤
1. **克隆并安装依赖**
```bash
git clone https://github.com/furrium/forumlify.git
cd forumlify
npm install
```
2. **准备数据库**(以本机 PostgreSQL 为例)
```bash
# 创建数据库和用户(与 docker-compose.yml 默认一致)
psql -U postgres -c "CREATE USER forumlify WITH PASSWORD '123456';"
psql -U postgres -c "CREATE DATABASE forumlify OWNER forumlify;"
# 导入表结构
psql -U forumlify -d forumlify -f schema.sql
```
3. **配置环境变量**(可选,均有默认值)
| 变量 | 默认值 | 说明 |
|------|--------|------|
| `DATABASE_URL` | `postgresql://forumlify:123456@localhost:5432/forumlify` | PostgreSQL 连接串 |
| `PORT` | `3000` | HTTP 监听端口 |
| `JWT_SECRET` | `forumlify-secret-key-change-me-in-production` | JWT 签名密钥,**生产环境务必修改** |
```bash
# 例如:
export DATABASE_URL=postgresql://forumlify:123456@localhost:5432/forumlify
export JWT_SECRET=your-own-secret-key
```
4. **启动**
```bash
npm start
```
应用运行在 `http://localhost:3000`,API 在 `http://localhost:3000/api`。
#### 前端配置
前端页面为 `index.html`,相关行为可在 `config.js` 中调整:
| 配置项 | 默认值 | 说明 |
|--------|--------|------|
| `FORUM_NAME` | `Forumlify` | 论坛名称(左上角显示) |
| `ENABLE_CAPTCHA` | `true` | 发帖/注册的人机验证(10 以内加减法) |
| `SERVER_PORT` | `null` | 可选:服务端监听端口(仅服务端读取,浏览器端忽略)。优先级:环境变量 `PORT` > `SERVER_PORT` > 默认 `3000`。设为 `null` 时使用环境变量或默认值 |
#### 上传目录
帖子图片默认保存在 `uploads/` 目录(Docker 部署时通过 volume 挂载到 `/app/uploads`),源码部署时请确保该目录有写入权限:
```bash
mkdir -p uploads && chmod 755 uploads
```
+5
View File
@@ -16,6 +16,11 @@ const CONFIG = {
// 是否开启发帖/注册的人机验证(10以内加减法)
ENABLE_CAPTCHA: true,
// 可选:服务端监听端口(仅服务端读取,浏览器端忽略)
// 优先顺序:环境变量 PORT > 此处配置 > 默认 3000
// 设为 null 则使用环境变量或默认值
SERVER_PORT: null,
};
// ===== 不要修改下面 =====
+1863
View File
File diff suppressed because it is too large. Load diff
+6 -1
View File
@@ -13,7 +13,12 @@ const path = require('path');
const fs = require('fs');
const app = express();
const PORT = process.env.PORT || 3000;
// 服务端配置(config.js,浏览器端加载同名文件但不影响服务端)
const CONFIG = require('./config');
// 监听端口:环境变量 PORT 优先,其次 config.js 的 SERVER_PORT,最后默认 3000
const PORT = process.env.PORT || CONFIG.SERVER_PORT || 3000;
const JWT_SECRET = process.env.JWT_SECRET || 'forumlify-secret-key-change-me-in-production';
// ============================================================