-
Notifications
You must be signed in to change notification settings - Fork 296
/
server.clj
48 lines (38 loc) · 1.6 KB
/
server.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
; Copyright 2013 Relevance, Inc.
; Copyright 2014 Cognitect, Inc.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0)
; which can be found in the file epl-v10.html at the root of this distribution.
;
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
;
; You must not remove this notice, or any other, from this software.
(ns server-with-links.server
(:require [server-with-links.service :as service]
[io.pedestal.service.http :as bootstrap]))
(def service-instance
"Global var to hold service instance."
nil)
(defn create-server
"Standalone dev/prod mode."
[& [opts]]
(alter-var-root #'service-instance
(constantly (bootstrap/create-server (merge service/service opts)))))
(defn -main [& args]
(println "Creating server...")
(create-server)
(println "Server created. Awaiting connections.")
(bootstrap/start service-instance))
;; Container prod mode for use with the pedestal.servlet.ClojureVarServlet class.
(defn servlet-init [this config]
(require 'server-with-links.service)
(alter-var-root #'service-instance (bootstrap/create-servlet service/service))
(bootstrap/start service-instance)
(.init (::bootstrap/servlet service-instance) config))
(defn servlet-destroy [this]
(bootstrap/stop service-instance)
(alter-var-root #'service-instance nil))
(defn servlet-service [this servlet-req servlet-resp]
(.service ^javax.servlet.Servlet (::bootstrap/servlet service-instance)
servlet-req servlet-resp))