Liking cljdoc? Tell your friends :D

zeph.server

Cross-platform HTTP server using Java NIO. API compatible with http-kit.

Cross-platform HTTP server using Java NIO.
API compatible with http-kit.
raw docstring

run-serverclj

(run-server handler
            &
            [{:keys [port ip thread static-root ssl? cert key keystore
                     keystore-password streaming? max-body idle-timeout]
              :or {port 8080
                   ip "0.0.0.0"
                   thread 1
                   ssl? false
                   streaming? true
                   max-body -1
                   idle-timeout 30000}
              :as opts}])

Start a cross-platform HTTP server using Java NIO.

handler - Ring handler function

Options: :port - Port to listen on (default: 8080) :ip - IP to bind (default: "0.0.0.0") :thread - Number of worker threads (default: 1) :worker-name-prefix - Ignored (for http-kit compatibility) :queue-size - Ignored (for http-kit compatibility) :max-body - Max request body size (default: 8MB) :max-line - Max request line size (default: 8KB)

:streaming? - Enable streaming request body (default: true) Large request bodies are streamed via InputStream instead of buffering in memory.

:idle-timeout - Connection idle timeout in milliseconds (default: 30000) Use 0 to disable idle timeout (useful for long-running requests).

;; Static file serving :static-root - Path to static files directory (optional) When set, serves static files from this directory. Falls back to handler if file not found.

;; SSL/TLS options (use :cert/:key for PEM or :keystore for PKCS12/JKS) :ssl? - Enable SSL/TLS (default: false) :cert - Path to certificate PEM file :key - Path to private key PEM file :keystore - Path to keystore file (PKCS12 or JKS) :keystore-password - Keystore password :keystore-type - Keystore type (default: PKCS12) :truststore - Path to truststore file (optional) :truststore-password - Truststore password :client-auth - Require client authentication (default: false) :protocols - Enabled TLS protocols (e.g. ["TLSv1.3" "TLSv1.2"]) :cipher-suites - Enabled cipher suites

Returns a function that stops the server when called. Call (stop-fn) or (stop-fn {:timeout ms}) to stop.

Example: ;; HTTP server (def stop (run-server handler {:port 8080}))

;; Serve static files from ./public (def stop (run-server handler {:port 8080 :static-root "./public"}))

;; Long-running request server (no idle timeout) (def stop (run-server handler {:port 8080 :idle-timeout 0}))

;; HTTPS server with PEM files (def stop (run-server handler {:port 8443 :ssl? true :cert "cert.pem" :key "key.pem"}))

;; HTTPS server with keystore (def stop (run-server handler {:port 8443 :ssl? true :keystore "keystore.p12" :keystore-password "secret"})) ;; later (stop)

Start a cross-platform HTTP server using Java NIO.

handler - Ring handler function

Options:
  :port              - Port to listen on (default: 8080)
  :ip                - IP to bind (default: "0.0.0.0")
  :thread            - Number of worker threads (default: 1)
  :worker-name-prefix - Ignored (for http-kit compatibility)
  :queue-size        - Ignored (for http-kit compatibility)
  :max-body          - Max request body size (default: 8MB)
  :max-line          - Max request line size (default: 8KB)

  :streaming?        - Enable streaming request body (default: true)
                       Large request bodies are streamed via InputStream
                       instead of buffering in memory.

  :idle-timeout      - Connection idle timeout in milliseconds (default: 30000)
                       Use 0 to disable idle timeout (useful for long-running requests).

  ;; Static file serving
  :static-root       - Path to static files directory (optional)
                       When set, serves static files from this directory.
                       Falls back to handler if file not found.

  ;; SSL/TLS options (use :cert/:key for PEM or :keystore for PKCS12/JKS)
  :ssl?              - Enable SSL/TLS (default: false)
  :cert              - Path to certificate PEM file
  :key               - Path to private key PEM file
  :keystore          - Path to keystore file (PKCS12 or JKS)
  :keystore-password - Keystore password
  :keystore-type     - Keystore type (default: PKCS12)
  :truststore        - Path to truststore file (optional)
  :truststore-password - Truststore password
  :client-auth       - Require client authentication (default: false)
  :protocols         - Enabled TLS protocols (e.g. ["TLSv1.3" "TLSv1.2"])
  :cipher-suites     - Enabled cipher suites

Returns a function that stops the server when called.
Call (stop-fn) or (stop-fn {:timeout ms}) to stop.

Example:
  ;; HTTP server
  (def stop (run-server handler {:port 8080}))

  ;; Serve static files from ./public
  (def stop (run-server handler {:port 8080 :static-root "./public"}))

  ;; Long-running request server (no idle timeout)
  (def stop (run-server handler {:port 8080 :idle-timeout 0}))

  ;; HTTPS server with PEM files
  (def stop (run-server handler {:port 8443
                                 :ssl? true
                                 :cert "cert.pem"
                                 :key "key.pem"}))

  ;; HTTPS server with keystore
  (def stop (run-server handler {:port 8443
                                 :ssl? true
                                 :keystore "keystore.p12"
                                 :keystore-password "secret"}))
  ;; later
  (stop)
sourceraw docstring

server-stop!clj

(server-stop! server & [opts])

Stop a server. http-kit compatible alias.

server - The stop function returned by run-server opts - {:timeout ms} (default 5000ms)

Stop a server. http-kit compatible alias.

server - The stop function returned by run-server
opts   - {:timeout ms} (default 5000ms)
sourceraw docstring

with-servercljmacro

(with-server [binding start-expr] & body)

Start a server, execute body, then stop the server.

Example: (with-server [stop (run-server handler {:port 8080})] (do-something))

Start a server, execute body, then stop the server.

Example:
  (with-server [stop (run-server handler {:port 8080})]
    (do-something))
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close