Method: FunctionsFramework::Server#initialize

Defined in:
lib/functions_framework/server.rb

#initialize(function, globals) {|FunctionsFramework::Server::Config| ... } ⇒ Server

Create a new web server given a function definition, a set of application globals, and server configuration.

To configure the server, pass a block that takes a Config object as the parameter. This block is the only opportunity to modify the configuration; once the server is initialized, configuration is frozen.

Parameters:

  • function (FunctionsFramework::Function)

    The function to execute.

  • globals (Hash)

    Globals to pass to invocations. This hash should normally be frozen so separate function invocations cannot interfere with one another's globals.

Yields:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/functions_framework/server.rb', line 45

def initialize function, globals
  super()
  @config = Config.new
  yield @config if block_given?
  @config.freeze
  @function = function
  @app =
    case function.type
    when :http
      HttpApp.new function, globals, @config
    when :cloud_event
      EventApp.new function, globals, @config
    else
      raise "Unrecognized function type: #{function.type}"
    end
  @server = nil
  @signals_installed = false
end