目录
1. 背景
postman强制登录,不登录不给用,登录也就算了,还默认自动同步,这样的话就尴尬了。有些私人的接口啊,私人的账密啊,私人的token啊,真心不敢同步到别人的服务器上,把隐私安全寄托在别人的节操上。
一直在找平替,也有几家国产,现在不都喊着支持国货嘛,试用了一下,也是各种登录,各种同步,各种大版本升级,然后小版本的内容就不见了,寻寻觅觅的,可算是找到了一款开源的平替。
hoppscotch
,以前还叫做postwoman
,看看这个命名,想干啥懂的都懂。
看了开源代码的文档,只说了原生docker的用法,自带的docker-compose又很多坑,本科普就是把这个过程捋一遍,理论上照着做就行!
2. 前期准备
2.1 准备docker-compose文件,两个版本,一个3合1,一个分开
-
稍微介绍一下,
hoppscotch
的服务容器分为4个,1个容器是api测试平台hoppscotch-frontend
,端口是3000,(也就是常用的使用界面),即前台界面,如图,眼熟吧,跟postman差不多,主要使用的也是这个:
-
1个容器是后端接口
hoppscotch-backend
,端口是3170,没啥好说,所有核心服务都在这个里 -
1个容器是后台管理平台
hoppscotch-admin
,端口是3100,如图
-
还有一个容器就是postgresql数据库了,hoppscotch不能换数据库,说是用了postgresql的什么json独有的功能,不能换mysql
2.1.1 3合1版本(推荐)
- 推荐使用这个版本,可以直接把3个服务合成1个启动
- 只需要确认一下容器
hoppscotch-db
数据库配置就行,完全可以一点不改,直接拿来就用
# To make it easier to self-host, we have a preset docker compose config that also
# has a container with a Postgres instance running.
# You can tweak around this file to match your instances
services:
# The service that spins up all 3 services at once in one container
hoppscotch-aio:
container_name: hoppscotch-aio
image: hoppscotch/hoppscotch
restart: unless-stopped
env_file:
- ./.env
depends_on:
hoppscotch-db:
condition: service_healthy
ports:
- "3000:3000"
- "3100:3100"
- "3170:3170"
- "3080:80"
# The preset DB service, you can delete/comment the below lines if
# you are using an external postgres instance
# This will be exposed at port 5432
hoppscotch-db:
image: postgres:15
ports:
- "5432:5432"
volumes:
- ./postgres-data:/var/lib/postgresql/data
environment:
# The default user defined by the docker image
POSTGRES_USER: postgres
# NOTE: Please UPDATE THIS PASSWORD!
POSTGRES_PASSWORD: password
POSTGRES_DB: hoppscotch
healthcheck:
test:
[
"CMD-SHELL",
"sh -c 'pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}'",
]
interval: 5s
timeout: 5s
retries: 10
2.1.2 独立版本
- 这个版本就是多个容器都分开了,各起各的
- 直接在下面的docker-compose里修改成你自己版本的就行,主要就是改一下数据库连接
hoppscotch-backend
容器里的DATABASE_URL
,数据库连接,账号是postgresql默认的,可以不改,密码如果想改,要改对应的hoppscotch-db
容器里的postgresql配置里的POSTGRES_PASSWORD
字段,172.17.0.1
这个要看你本地的docker 网络 ip(一般本地开发都用127.0.0.1,这个就是docker自己的本地开发ip,类似的),理论上应该是这个,可以通过ifconfig
,找到docker0
,复制列出来的ip就行- 其实除了
172.17.0.1
要确认一下是否一样,其他的都可以不改的
# To make it easier to self-host, we have a preset docker compose config that also
# has a container with a Postgres instance running.
# You can tweak around this file to match your instances
services:
# This service runs the backend app in the port 3170
hoppscotch-backend:
container_name: hoppscotch-backend
image: hoppscotch/hoppscotch-backend
restart: unless-stopped
env_file:
- ./.env
environment:
# Edit the below line to match your PostgresDB URL if you have an outside DB (make sure to update the .env file as well)
- DATABASE_URL=postgresql://postgres:password@172.17.0.1:5432/hoppscotch?connect_timeout=300
depends_on:
hoppscotch-db:
condition: service_healthy
ports:
- "3180:80"
- "3170:3170"
# The main hoppscotch app. This will be hosted at port 3000
# NOTE: To do TLS or play around with how the app is hosted, you can look into the Caddyfile for
# the SH admin dashboard server at packages/hoppscotch-selfhost-web/Caddyfile
hoppscotch-frontend:
container_name: hoppscotch-frontend
image: hoppscotch/hoppscotch-frontend
restart: unless-stopped
env_file:
- ./.env
depends_on:
- hoppscotch-backend
ports:
- "3080:80"
- "3000:3000"
# The Self Host dashboard for managing the app. This will be hosted at port 3100
# NOTE: To do TLS or play around with how the app is hosted, you can look into the Caddyfile for
# the SH admin dashboard server at packages/hoppscotch-sh-admin/Caddyfile
hoppscotch-admin:
container_name: hoppscotch-admin
image: hoppscotch/hoppscotch-admin
restart: unless-stopped
env_file:
- ./.env
depends_on:
- hoppscotch-backend
ports:
- "3280:80"
- "3100:3100"
# The preset DB service, you can delete/comment the below lines if
# you are using an external postgres instance
# This will be exposed at port 5432
hoppscotch-db:
image: postgres:15
ports:
- "5432:5432"
volumes:
- ./postgres-data:/var/lib/postgresql/data
environment:
# The default user defined by the docker image
POSTGRES_USER: postgres
# NOTE: Please UPDATE THIS PASSWORD!
POSTGRES_PASSWORD: password
POSTGRES_DB: hoppscotch
healthcheck