用于开发和测试的虚拟 Pusher 服务器。
A fake Pusher server for development and testing.
When run, an entire fake service starts on two random open ports. A Pusher account is not required to make connections to the fake service. If you need to know the host or port, you can find the values in the configuration.
The project fully replaces the Pusher service with a local version for testing and development. Using the service as a replacement for production is not recommended.
require "pusher-fake/support/rspec"require "pusher-fake/support/cucumber"Using Zeus requires a custom plan. See an example plan for the configuration necessary.
require "pusher-fake/support/base"
# Reset the channels after each test:
PusherFake::Channel.resetIn a Rails initializer, or any file executed during loading:
# Avoid running outside of development, if it's a global file.
if Rails.env.development?
# Set the Pusher configuration, if it's not done elsewhere.
Pusher.app_id = "MY_TEST_ID"
Pusher.key = "MY_TEST_KEY"
Pusher.secret = "MY_TEST_SECRET"
# Require the base file, which starts the socket and web servers.
#
# If you're including this file in different processes, you may want to add
# another check or even possibly hard code the socket and web ports.
require "pusher-fake/support/base"
endIf you're using Foreman, or something similar, you'll want to limit the fake to a single process:
if ENV["PUSHER_FAKE"]
require "pusher-fake/support/base"
endweb: PUSHER_FAKE=1 bundle exec unicorn ...
worker: bundle exec ...If you're creating a Pusher::Client instance and wish to use the fake, you need to provide the options.
Pusher::Client.new({
key: Pusher.key,
app_id: Pusher.app_id,
secret: Pusher.secret
}.merge(PusherFake.configuration.web_options))If you need to run the fake as a standalone service, perhaps when using Docker, there is a pusher-fake binary available.
…Note that the binary does not support SSL options since they're forwarded to the server libraries. If you need SSL support in the binary, it's recommended you copy the included binary into your own project and set the appropriate configuration there instead.
Note that the application ID, API key, and token are automatically set to the Pusher values when using an included support file.
| Setting | Description |
|---|---|
| app_id | The Pusher application ID. |
| key | The Pusher API key. |
| logger | An IO instance for verbose logging. |
| secret | The Pusher API token. |
| socket_options | Socket server options. See EventMachine::WebSocket.start for options. |
| verbose | Enable verbose logging. |
| web_options | Web server options. See Thin::Server for options. |
| webhooks | Array of webhook URLs. |
# Single setting.
PusherFake.configuration.verbose = true
# Multiple settings.
PusherFake.configure do |configuration|
configuration.logger = Rails.logger
configuration.verbose = true
endThe WebSocket server is provided all socket_options, allowing you to set the secure and tls_options options to create a secure server.
The web server passes all web_options, besides host and port, to the Thin backend via attribute writers, allowing you to set the ssl and ssl_options options.
If you would like to force TLS for the JavaScript client, you can provide a forceTLS option:
var instance = ;pusher-fake uses the MIT license. See LICENSE for more details.
暂无开放 Issues,或尚未同步最近议题。