<commit_before>(ns hatnik.web.server.handler
  (:require clojure.pprint
            [compojure.core :refer :all]
            [compojure.handler :as handler]
            [compojure.route :as route]
            [taoensso.timbre :as timbre]

            [hatnik.web.server.renderer :as renderer]
            [hatnik.web.server.projects :refer [projects-api]]
            [hatnik.web.server.actions :refer [actions-api]]
            [hatnik.web.server.login :refer [login-api]]
            [hatnik.config :refer [config]]

            [ring.middleware.json :as json]
            [ring.adapter.jetty :refer [run-jetty]]
            [ring.middleware.stacktrace :as stacktrace]))

(timbre/set-level! (:log-level config))

(defroutes app-routes
  (GET "/" [] renderer/core-page)
  (context "/api" []
           (context "/projects" [] projects-api)
           (context "/actions" [] actions-api)
           login-api)
  (route/resources "/")
  (route/not-found "Not Found"))

(defn dump-request [handler]
  (fn [req]
    (timbre/debug "Request:" req)
    (let [resp (handler req)]
      (timbre/debug "Response:" resp)
      resp)))

(def app
  (-> #'app-routes
      dump-request
      (handler/site {:session {:cookie-attrs {:max-age 3600
                                              :http-only true}}})
      (json/wrap-json-body {:keywords? true})
      json/wrap-json-response
      stacktrace/wrap-stacktrace))

(comment

   (def server (run-jetty #(app %) {:port 8080 :join? false}))

   (.stop server)
)
<commit_msg>Add mock for /api/library-version method.<commit_after>(ns hatnik.web.server.handler
  (:require clojure.pprint
            [compojure.core :refer :all]
            [compojure.handler :as handler]
            [compojure.route :as route]
            [taoensso.timbre :as timbre]

            [hatnik.web.server.renderer :as renderer]
            [hatnik.web.server.projects :refer [projects-api]]
            [hatnik.web.server.actions :refer [actions-api]]
            [hatnik.web.server.login :refer [login-api]]
            [hatnik.config :refer [config]]

            [ring.util.response :as resp]
            [ring.middleware.json :as json]
            [ring.adapter.jetty :refer [run-jetty]]
            [ring.middleware.stacktrace :as stacktrace]))

(timbre/set-level! (:log-level config))

(defn library-version [group artifact]
  (resp/response
   {:result :ok
    :version "1.6.0"}))

(defroutes app-routes
  (GET "/" [] renderer/core-page)
  (context "/api" []
           (context "/projects" [] projects-api)
           (context "/actions" [] actions-api)
           login-api
           (GET "/library-version" [group artifact] (library-version group artifact)))
  (route/resources "/")
  (route/not-found "Not Found"))

(defn dump-request [handler]
  (fn [req]
    (timbre/debug "Request:" req)
    (let [resp (handler req)]
      (timbre/debug "Response:" resp)
      resp)))

(def app
  (-> #'app-routes
      dump-request
      (handler/site {:session {:cookie-attrs {:max-age 3600
                                              :http-only true}}})
      (json/wrap-json-body {:keywords? true})
      json/wrap-json-response
      stacktrace/wrap-stacktrace))

(comment

   (def server (run-jetty #(app %) {:port 8080 :join? false}))

   (.stop server)
)

{'fraction_non_alphanumeric': 0.15059324612108305, 'fraction_numerical': 0.005780346820809248, 'mean_word_length': 2.1798839458413926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3742192', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1045, 'n_words': 229}