Class: FunctionsFramework::Server::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/functions_framework/server.rb

Overview

The web server configuration. This object is yielded from the FunctionsFramework::Server constructor and can be modified at that point. Afterward, it is available from #config but it is frozen.

Instance Method Summary collapse

Constructor Details

#initializeConfig

Create a new config object with the default settings



213
214
215
216
217
218
219
220
221
# File 'lib/functions_framework/server.rb', line 213

def initialize
  self.rack_env = nil
  self.bind_addr = nil
  self.port = nil
  self.min_threads = nil
  self.max_threads = nil
  self.show_error_details = nil
  self.logger = nil
end

Instance Method Details

#bind_addrString

Returns the current bind address.

Returns:

  • (String)


297
298
299
# File 'lib/functions_framework/server.rb', line 297

def bind_addr
  @bind_addr
end

#bind_addr=(bind_addr) ⇒ Object

Set the bind address, or nil to use the default.

Parameters:

  • bind_addr (String, nil)


236
237
238
# File 'lib/functions_framework/server.rb', line 236

def bind_addr= bind_addr
  @bind_addr = bind_addr || ::ENV["FUNCTION_BIND_ADDR"] || "0.0.0.0"
end

#loggerLogger

Returns the logger.

Returns:

  • (Logger)


337
338
339
# File 'lib/functions_framework/server.rb', line 337

def logger
  @logger
end

#logger=(logger) ⇒ Object

Set the logger for server messages, or nil to use the global default.

Parameters:

  • logger (Logger)


281
282
283
# File 'lib/functions_framework/server.rb', line 281

def logger= logger
  @logger = logger || ::FunctionsFramework.logger
end

#max_threadsInteger

Returns the maximum number of worker threads in the thread pool.

Returns:

  • (Integer)


321
322
323
# File 'lib/functions_framework/server.rb', line 321

def max_threads
  @max_threads || 16
end

#max_threads=(max_threads) ⇒ Object

Set the maximum number of worker threads, or nil to use the default.

Parameters:

  • max_threads (Integer, nil)


260
261
262
# File 'lib/functions_framework/server.rb', line 260

def max_threads= max_threads
  @max_threads = (max_threads || ::ENV["FUNCTION_MAX_THREADS"])&.to_i
end

#min_threadsInteger

Returns the minimum number of worker threads in the thread pool.

Returns:

  • (Integer)


313
314
315
# File 'lib/functions_framework/server.rb', line 313

def min_threads
  @min_threads || 1
end

#min_threads=(min_threads) ⇒ Object

Set the minimum number of worker threads, or nil to use the default.

Parameters:

  • min_threads (Integer, nil)


252
253
254
# File 'lib/functions_framework/server.rb', line 252

def min_threads= min_threads
  @min_threads = (min_threads || ::ENV["FUNCTION_MIN_THREADS"])&.to_i
end

#portInteger

Returns the current port number.

Returns:

  • (Integer)


305
306
307
# File 'lib/functions_framework/server.rb', line 305

def port
  @port
end

#port=(port) ⇒ Object

Set the port number, or nil to use the default.

Parameters:

  • port (Integer, nil)


244
245
246
# File 'lib/functions_framework/server.rb', line 244

def port= port
  @port = (port || ::ENV["PORT"] || 8080).to_i
end

#rack_envString

Returns the current Rack environment.

Returns:

  • (String)


289
290
291
# File 'lib/functions_framework/server.rb', line 289

def rack_env
  @rack_env
end

#rack_env=(rack_env) ⇒ Object

Set the Rack environment, or nil to use the default.

Parameters:

  • rack_env (String, nil)


227
228
229
230
# File 'lib/functions_framework/server.rb', line 227

def rack_env= rack_env
  @rack_env = rack_env || ::ENV["RACK_ENV"] ||
              (::ENV["K_REVISION"] ? "production" : "development")
end

#show_error_details=(show_error_details) ⇒ Object

Set whether to show detailed error messages, or nil to use the default.

Parameters:

  • show_error_details (Boolean, nil)


268
269
270
271
272
273
274
275
# File 'lib/functions_framework/server.rb', line 268

def show_error_details= show_error_details
  @show_error_details =
    if show_error_details.nil?
      !::ENV["FUNCTION_DETAILED_ERRORS"].to_s.empty?
    else
      show_error_details ? true : false
    end
end

#show_error_details?Boolean

Returns whether to show detailed error messages.

Returns:

  • (Boolean)


329
330
331
# File 'lib/functions_framework/server.rb', line 329

def show_error_details?
  @show_error_details.nil? ? (@rack_env == "development") : @show_error_details
end