AppDelegate.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright 2016, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import Cocoa
  17. @NSApplicationMain
  18. class AppDelegate: NSObject, NSApplicationDelegate {
  19. @IBOutlet var window: NSWindow!
  20. var echoProvider: Echo_EchoProvider!
  21. var insecureServer: ServiceServer!
  22. var secureServer: ServiceServer!
  23. func applicationDidFinishLaunching(_: Notification) {
  24. // instantiate our custom-written application handler
  25. echoProvider = EchoProvider()
  26. // create and start a server for handling insecure requests
  27. insecureServer = ServiceServer(address: "localhost:8081",
  28. serviceProviders: [echoProvider])
  29. insecureServer.start()
  30. // create and start a server for handling secure requests
  31. let certificateURL = Bundle.main.url(forResource: "ssl", withExtension: "crt")!
  32. let keyURL = Bundle.main.url(forResource: "ssl", withExtension: "key")!
  33. secureServer = ServiceServer(address: "localhost:8443",
  34. certificateURL: certificateURL,
  35. keyURL: keyURL,
  36. serviceProviders: [echoProvider])
  37. secureServer.start()
  38. }
  39. }