blog-site

git clone git://git.lin.moe/blog-site.git

  1---
  2title: "hack-chat 使用指南"
  3date: 2021-05-04T22:49:36+08:00
  4---
  5
  6
  7* [github](https://github.com/hack-chat/main)  
  8
  9* [hack.chat](https://hack.chat)  
 10
 11* [beta.hack.chat](https://beta.hack.chat)  
 12
 13> 笔者已改为使用 IRC,IRC 也有 webirc 之类的 websocket 实现,所以这个项目就有点显得鸡肋了
 14
 15## hack.chat 是什么
 16>hack.chat is a minimal, distraction-free, accountless, logless, disappearing chat service which is easily deployable as your own service.   
 17>hack.chat 是一个极简的,分发自由,无账户,无日志,易失的,易部署的聊天服务。  
 18>The current client comes bundled with LaTeX rendering provided by KaTeX and code syntax highlighting provided by highlight.js.  
 19>现版本的客户端使用了 KaTeX 提供的 LaTex 渲染和 highlight.js 提供的代码语法高亮  
 20
 21简单来说,就是一个 web 聊天室, WTFPL 开源。服务端不存储任何有状态记录,消息只分发给同一时刻连接到同一个 websocket 池的客户端。不支持端对端加密。
 22
 23
 24## 常用指令
 25    /whispher <someone> [text]  # 发送指定用户可见的消息
 26    /stats  # 查看服务器信息
 27    /move <chanel> # 不刷新页面移动到新频道,只会改变自己的状态,且浏览器上方的 url 不会变。可能引起混淆,尽量少用。
 28
 29## 聊天
 30支持大部分常用的 Markdown 语法,支持 Latex 公式。   
 31
 32不能直接显示图片。(虽然配置里有个 imgur 选项,不知道怎么用)   
 33
 34shift+Enter 消息换行。  
 35
 36## 侧边栏
 37鼠标移到页面右侧边缘,会弹出一个侧边栏,提供的选项有
 38* 改变主题
 39* 开启通知(桌面通知或声音)
 40* 邀请用户进入另一个随机产生的频道
 41
 42## 部署
 43### 1. 安装 nodejs 和 npm
 44### 2. git clone https://github.com/hack-chat/main
 45### 3. cd main && npm install
 46会要求输入盐值,管理员用户名密码,websocket 监听端口    
 47
 48管理员登录方式是在进入聊天室时,使用 \<admin_user\>#\<admin_password\>,如 lindsay#123456  
 49
 50### 4. npm start
 51启动了两个应用,一个监听在 3000 端口,提供前端服务,一个监听在 install 时配置的端口。  
 52
 53### 5. 修改前端 websocket 路径配置
 54在 client/client.js 找到  
 55
 56> var wsPath = ':6060';  
 57
 58这一行。   
 59
 60这里的值修改成想要的, 不一定是在第 3 步中设置的端口。    
 61
 62以 https://chat.koi.moe 为例,在 nginx 中设置了
 63```
 64location /ws {
 65    proxy_pass http://127.0.0.1:6060
 66}
 67```
 68那么这里的值就改成    
 69
 70> var wsPath = '/ws';
 71
 72### 6. nginx 配置  
 73```
 74upstream websocket {
 75        server 127.0.0.1:6060;
 76}
 77server {
 78        listen 443 http2 ssl;
 79        listen [::]:443 http2 ssl;
 80        server_name chat.koi.moe;
 81
 82        ssl_certificate <path_to_cert>;
 83        ssl_certificate_key <path_to_key;
 84
 85        #client_max_body_size 0;
 86
 87
 88        location / {
 89                # proxy_pass http://127.0.0.1:3000/; # 二选一
 90                root <project_location>/client;
 91        }
 92
 93        # 下面这条可选,相应 client.js 文件会不一样,请自行斟酌。
 94        location /ws {
 95                rewrite ^/ws / break;
 96                proxy_pass http://websocket;
 97
 98                proxy_http_version 1.1;
 99                proxy_set_header Upgrade $http_upgrade;
100                proxy_set_header Connection "upgrade";
101        }
102
103}
104```
105在 location / 中,可以转到 3000 端口,也可以直接指向项目的静态目录。  
106
107个人觉得后者执行效率更高。  
108
109### 7. 启动
110> npm start
111
112
113### 8. 其他
114可以在 client.js 文件中找到  
115>var frontpage = [
116>        .....
117>    ]  
118
119可更改首页描述,这里的 Markdown 语法解析跟聊天室消息的解析一样  
120诸如域名解析一类的东西就不赘述了