我如何使用 Postman 在 Docker 内连接到 laravel-websockets 运行
How may I use Postman to connect to laravel-websockets running within Docker
我想测试通过 laravel-websockets 接收从我的 laravel 应用广播的事件。该应用程序和 websockets 运行 在 docker 中成功,我有主管保持一切正常 运行。我的问题是,使用 Postman 的 websocket 功能,我无法连接到 docker (ws://127.0.0.1:6001) 内的 websockets 服务器 运行。我得到 404。
docker-compose.yml
version: '2'
services:
ace-contact-import:
build:
context: .
dockerfile: ./docker/Dockerfile
ports:
- "8787:80"
- "6001:6001"
volumes:
- ./:/var/www/
tty: true
composer:
build:
context: .
dockerfile: ./docker/composer/Dockerfile
depends_on:
- ace-contact-import
volumes_from:
- ace-contact-import
tty: true
redis:
image: redis:alpine
container_name: ace-contact-import-redis
command: redis-server --appendonly yes --requirepass "${REDIS_PASSWORD}"
volumes:
- ./data/redis:/data
ports:
- "8002:6379"
volumes:
logvolume01: {}
websockets.php
'apps' => [
[
'id' => env('PUSHER_APP_ID'),
'name' => env('APP_NAME'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'path' => env('PUSHER_APP_PATH'),
'capacity' => null,
'enable_client_messages' => false, // peer-to-peer client messages
'enable_statistics' => false,
],
],
broadcasting.php
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY', 'app-key'),
'secret' => env('PUSHER_APP_SECRET', 'app-secret'),
'app_id' => env('PUSHER_APP_ID', 'app-id'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'host' => env('LARAVEL_WEBSOCKETS_HOST', '127.0.0.1'),
'port' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
'scheme' => env('LARAVEL_WEBSOCKETS_SCHEME', 'http'),
'encrypted' => false, // todo
'useTLS' => env('PUSHER_SCHEME') === 'https', // todo
],
],
.env
PUSHER_APP_ID=12345
PUSHER_APP_KEY=ABCDEFG
PUSHER_APP_SECRET=HIJKLMNOP
PUSHER_APP_CLUSTER=mt1
LARAVEL_WEBSOCKETS_HOST=host.docker.internal # also tried 127.0.0.1
LARAVEL_WEBSOCKETS_PORT=6001
LARAVEL_WEBSOCKETS_SCHEME=http
# For Echo (Client side)
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
创建到您的 websocket 实例的原始 ws 连接:
ws://localhost:6001/app/abcdef?protocol=7&client=js&version=7.0.6&flash=false
abcdef 是 PUSHER_APP_KEY ,它应该与您的 .env 文件中的内容相匹配。
如果您的端口不是 6001,请在 URL.
中更改它
连接后,您可以在 Postman 中撰写消息以订阅您的频道:
{
"event":"pusher:subscribe",
"data":{
"auth":"",
"channel":"your-channel-name-here"
}
}
就是这样!当消息从服务器广播时,它们将出现在屏幕底部的消息页面中。
我想测试通过 laravel-websockets 接收从我的 laravel 应用广播的事件。该应用程序和 websockets 运行 在 docker 中成功,我有主管保持一切正常 运行。我的问题是,使用 Postman 的 websocket 功能,我无法连接到 docker (ws://127.0.0.1:6001) 内的 websockets 服务器 运行。我得到 404。
docker-compose.yml
version: '2'
services:
ace-contact-import:
build:
context: .
dockerfile: ./docker/Dockerfile
ports:
- "8787:80"
- "6001:6001"
volumes:
- ./:/var/www/
tty: true
composer:
build:
context: .
dockerfile: ./docker/composer/Dockerfile
depends_on:
- ace-contact-import
volumes_from:
- ace-contact-import
tty: true
redis:
image: redis:alpine
container_name: ace-contact-import-redis
command: redis-server --appendonly yes --requirepass "${REDIS_PASSWORD}"
volumes:
- ./data/redis:/data
ports:
- "8002:6379"
volumes:
logvolume01: {}
websockets.php
'apps' => [
[
'id' => env('PUSHER_APP_ID'),
'name' => env('APP_NAME'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'path' => env('PUSHER_APP_PATH'),
'capacity' => null,
'enable_client_messages' => false, // peer-to-peer client messages
'enable_statistics' => false,
],
],
broadcasting.php
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY', 'app-key'),
'secret' => env('PUSHER_APP_SECRET', 'app-secret'),
'app_id' => env('PUSHER_APP_ID', 'app-id'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'host' => env('LARAVEL_WEBSOCKETS_HOST', '127.0.0.1'),
'port' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
'scheme' => env('LARAVEL_WEBSOCKETS_SCHEME', 'http'),
'encrypted' => false, // todo
'useTLS' => env('PUSHER_SCHEME') === 'https', // todo
],
],
.env
PUSHER_APP_ID=12345
PUSHER_APP_KEY=ABCDEFG
PUSHER_APP_SECRET=HIJKLMNOP
PUSHER_APP_CLUSTER=mt1
LARAVEL_WEBSOCKETS_HOST=host.docker.internal # also tried 127.0.0.1
LARAVEL_WEBSOCKETS_PORT=6001
LARAVEL_WEBSOCKETS_SCHEME=http
# For Echo (Client side)
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
创建到您的 websocket 实例的原始 ws 连接:
ws://localhost:6001/app/abcdef?protocol=7&client=js&version=7.0.6&flash=false
abcdef 是 PUSHER_APP_KEY ,它应该与您的 .env 文件中的内容相匹配。 如果您的端口不是 6001,请在 URL.
中更改它连接后,您可以在 Postman 中撰写消息以订阅您的频道:
{
"event":"pusher:subscribe",
"data":{
"auth":"",
"channel":"your-channel-name-here"
}
}
就是这样!当消息从服务器广播时,它们将出现在屏幕底部的消息页面中。