Configuring the server

You can set different configurations per environment dev, prod, test or global by creating a file in config/env/. For instance, you can create a config/env/dev.jl file with the following content:

using Genie, Logging

Genie.Configuration.config!(
  server_port                     = 8000,
  server_host                     = "127.0.0.1",
  log_level                       = Logging.Info,
  log_to_file                     = false,
  server_handle_static_files      = true,
  path_build                      = "build",
  format_julia_builds             = true,
  format_html_output              = true,
  watch                           = true
)

ENV["JULIA_REVISE"] = "auto"

This file will be loaded when ENV[GENIE_ENV]=dev. Then, for production you can add another file config/env/prod.jl with:

using Genie, Logging

Genie.Configuration.config!(
  server_port                     = 8000,
  server_host                     = "0.0.0.0",
  log_level                       = Logging.Error,
  log_to_file                     = false,
  server_handle_static_files      = true, # for best performance set up Nginx or Apache web proxies and set this to false
  path_build                      = "build",
  format_julia_builds             = false,
  format_html_output              = false
)

ENV["JULIA_REVISE"] = "off"

Finally, if you create a config/env/global.jl file, it will be loaded for all environments.

The configuration is stored in a Genie.Configuration.Settings struct, which has these fields:

  • server_port::Int: the port for running the web server (default 8000)
  • server_host::String: the host for running the web server (default "127.0.0.1")
  • server_document_root::String: path to the document root (default "public/")
  • server_handle_static_files::Bool: if true, Genie will also serve static files. In production, it is recommended to serve static files with a web server like Nginx.
  • server_signature::String: Genie's signature used for tagging the HTTP responses. If empty, it will not be added.
  • app_env::String: the environment in which the app is running (dev, test, or prod)
  • cors_headers::Dict{String,String}: default Access-Control-* CORS settings
  • cors_allowed_origins::Vector{String}: allowed origin hosts for CORS settings
  • log_level::Logging.LogLevel: logging severity level
  • log_to_file::Bool: if true, information will be logged to file besides REPL
  • log_requests::Bool: if true, requests will be automatically logged
  • inflector_irregulars::Vector{Tuple{String,String}}: additional irregular singular-plural forms to be used by the Inflector
  • run_as_server::Bool: when true the server thread is launched synchronously to avoid that the script exits
  • websockets_server::Bool: if true, the websocket server is also started together with the web server
  • websockets_port::Int: the port for the websocket server (default server_port)
  • initializers_folder::String: the folder where the initializers are located (default "initializers/")
  • path_config::String: the path to the configurations folder (default "config/")
  • path_env::String: the path to the environment files (default "<path_config>/env/")
  • path_app::String: the path to the app files (default "app/")
  • html_parser_close_tag::String: default " /". Can be changed to an empty string "" so the single tags would not be closed.
  • webchannels_keepalive_frequency::Int: default 30000. Frequency in milliseconds to send keepalive messages to webchannel/websocket to keep the connection alive. Set to 0 to disable keepalive messages.

Moreover, the Configuration module provides helper functions such as env to check the current environment. See the API docs for more details.