src/prologue/core/nativesettings

Source   Edit  

Types

CtxSettings = ref object
  mimeDB*: MimeDB
  config*: TableRef[string, StringTableRef]
Context settings. Source   Edit  
Settings = ref object
  address*: string           ## The address of socket.
  port*: Port                ## The port of socket.
  listener*: Socket          ## listening socket to use (nil to auto create)
  debug*: bool               ## Debug mode(true is yes).
  reusePort*: bool           ## Use socket port in multiple times.
  bufSize*: int              ## Buffer size of sending static files.
Global settings for all handlers. Source   Edit  

Procs

func `[]`(settings: Settings; key: string): JsonNode {.inline,
    ...raises: [KeyError], tags: [], forbids: [].}
Retrieves the value for key from settings.data. Raises KeyError if key is not present. Source   Edit  
func getOrDefault(settings: Settings; key: string): JsonNode {.inline,
    ...raises: [], tags: [], forbids: [].}
Returns the value for key from settings.data, or nil if not present. Source   Edit  
func hasKey(settings: Settings; key: string): bool {.inline, ...raises: [],
    tags: [], forbids: [].}
Returns true if key exists in settings.data. Source   Edit  
proc loadSettings(configPath: string): Settings {....raises: [KeyError,
    EmptySecretKeyError, IOError, OSError, JsonParsingError, ValueError],
    tags: [ReadIOEffect, WriteIOEffect], forbids: [].}
Creates a Settings by reading and parsing the JSON file at configPath. The file must contain a "prologue" key with secretKey. Source   Edit  
func loadSettings(data: JsonNode): Settings {.
    ...raises: [KeyError, EmptySecretKeyError], tags: [], forbids: [].}
Creates a Settings from a JsonNode. The "prologue" key must contain at least secretKey. All other keys (e.g. maxBody) are preserved and accessible via settings["prologue"]. Source   Edit  
func newCtxSettings(): CtxSettings {....raises: [], tags: [], forbids: [].}
Creates a new CtxSettings with default MIME database and empty config. Source   Edit  
func newSettings(address = ""; port = Port(8080); debug = true;
                 reusePort = true; secretKey = randomString(8); appName = "";
                 bufSize = 40960; data: JsonNode = nil; listener: Socket = nil): Settings {.
    ...raises: [EmptySecretKeyError, KeyError], tags: [RootEffect], forbids: [].}

Creates a new Settings with the given parameters.

When data is provided, any existing "prologue" key inside it is preserved — only secretKey and appName are merged in. This allows passing custom settings like maxBody via data:

let settings = newSettings(
  data = %* {"prologue": {"maxBody": 1_000}},
  secretKey = "my-secret"
)

When data is nil, a default JSON tree is created containing only secretKey and appName.

Source   Edit  
func newSettingsFromJsonNode(settings: var Settings; data: JsonNode) {.inline,
    ...raises: [KeyError, EmptySecretKeyError], tags: [], forbids: [].}
Populates settings fields from data. The "prologue" key is required and must include secretKey. Standard fields (address, port, debug, reusePort, bufSize) are read from "prologue" if present; the full data tree is stored in settings.data for custom keys. Source   Edit