From a0be5a77539bdcadf329367b9d12e2cbea773356 Mon Sep 17 00:00:00 2001 From: Kwok-kuen Cheung Date: Thu, 1 Sep 2016 17:42:00 +0800 Subject: [PATCH] Disable pubsub and related features in slave mode Subscriptions and pubsub router will be run by skygear server in leader mode. Cloudcode should connect to leader by configuring the PUBSUB_URL environment variable. refs skygeario/skygear-server#105 --- main.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 12a9285cd..08255daa8 100644 --- a/main.go +++ b/main.go @@ -103,9 +103,12 @@ func main() { Config: config, } - internalHub := pubsub.NewHub() - initSubscription(config, connOpener, internalHub, pushSender) - initDevice(config, connOpener) + var internalHub *pubsub.Hub + if !config.App.Slave { + internalHub = pubsub.NewHub() + initSubscription(config, connOpener, internalHub, pushSender) + initDevice(config, connOpener) + } // Preprocessor preprocessorRegistry["notification"] = &pp.NotificationPreprocessor{ @@ -205,17 +208,19 @@ func main() { serveMux.Handle("/", r) // Following section is for Gateway - pubSub := pubsub.NewWsPubsub(nil) - pubSubGateway := router.NewGateway("", "/pubsub", serveMux) - pubSubGateway.GET(injector.InjectProcessors(&handler.PubSubHandler{ - WebSocket: pubSub, - })) - - internalPubSub := pubsub.NewWsPubsub(internalHub) - internalPubSubGateway := router.NewGateway("", "/_/pubsub", serveMux) - internalPubSubGateway.GET(injector.InjectProcessors(&handler.PubSubHandler{ - WebSocket: internalPubSub, - })) + if !config.App.Slave { + pubSub := pubsub.NewWsPubsub(nil) + pubSubGateway := router.NewGateway("", "/pubsub", serveMux) + pubSubGateway.GET(injector.InjectProcessors(&handler.PubSubHandler{ + WebSocket: pubSub, + })) + + internalPubSub := pubsub.NewWsPubsub(internalHub) + internalPubSubGateway := router.NewGateway("", "/_/pubsub", serveMux) + internalPubSubGateway.GET(injector.InjectProcessors(&handler.PubSubHandler{ + WebSocket: internalPubSub, + })) + } fileGateway := router.NewGateway("files/(.+)", "/files/", serveMux) fileGateway.GET(injector.Inject(&handler.AssetGetURLHandler{}))