<commit_before>(ns flycouchdb-webproject-example.handler
  (:use [compojure.core]
        [clojure.java.io :only (file resource)]
        [flycouchdb.migration :only (migrate flycouchdb)])
  (:require [compojure.handler :as handler]
            [compojure.route :as route]
            [cheshire.core :refer :all]
            [cheshire.generate :refer [add-encoder encode-str remove-encoder]]
            [ring.util.response :as resp]
            [ring.adapter.jetty :as jetty]
            [clojure.data.json :as json]))

(defn json-response [data & [status]]
  {:status  (or status 200)
   :headers {"Content-Type" "application/json"}
   :body    (json/write-str data)})

(defroutes app-routes
  (GET "/" req (resp/redirect (str (:context req) "/index.html")))
  (GET "/api/test/" [] (json-response {:response "response"}))
  (route/resources "/")
  (route/not-found (resp/resource-response "404.html" {:root "public"})))

(defn wrap-dir-index
  "Middleware to force request for / to return index.html"
  [handler] (fn [req] (handler (update-in req [:uri] #(if (= "/" %) "/index.html" %)))))

(defn execute-routing [] (-> app-routes
                           wrap-dir-index))

(def folder-path (resource "migrations/"))

(def flydb (flycouchdb folder-path))

(defn init []
  (println "Running migrations")
  (migrate flydb)
  (println "Migrations done!"))

(def app
  (handler/site (execute-routing)))

(defn -main [& [port]]
  (let [port (Integer. (or port (System/getenv "PORT")))]
    (jetty/run-jetty (execute-routing)
      {:port port :join? false})))<commit_msg>Adding commented code, so that we can fix the VFS problem<commit_after>(ns flycouchdb-webproject-example.handler
  (:use [compojure.core]
        [clojure.java.io :only (file resource)]
        [flycouchdb.migration :only (migrate flycouchdb)])
  (:require [compojure.handler :as handler]
            [compojure.route :as route]
            [cheshire.core :refer :all]
            [cheshire.generate :refer [add-encoder encode-str remove-encoder]]
            [ring.util.response :as resp]
            [ring.adapter.jetty :as jetty]
            [clojure.data.json :as json])
  (:import [java.io File]
           [java.net URL URLDecoder]
           [org.jboss.vfs VFS VirtualFile VirtualFileFilter]))

(defn json-response [data & [status]]
  {:status  (or status 200)
   :headers {"Content-Type" "application/json"}
   :body    (json/write-str data)})

(defroutes app-routes
  (GET "/" req (resp/redirect (str (:context req) "/index.html")))
  (GET "/api/test/" [] (json-response {:response "response"}))
  (route/resources "/")
  (route/not-found (resp/resource-response "404.html" {:root "public"})))

(defn wrap-dir-index
  "Middleware to force request for / to return index.html"
  [handler] (fn [req] (handler (update-in req [:uri] #(if (= "/" %) "/index.html" %)))))

(defn execute-routing [] (-> app-routes
                           wrap-dir-index))

(def folder-path (resource "migrations/"))

(def flydb (flycouchdb folder-path))

(defn init []
  (println "Running migrations")
  ;(clojure.pprint/pprint (.getProtocol folder-path))
  ;(->>
  ;  (.getPath folder-path)
  ;  (. URLDecoder decode)
  ;  (File.)
  ;  (.getAbsolutePath)
  ;  (. VFS getChild)
  ;  (.getChildren)
  ;  first
  ;  (.openStream)
  ;  slurp
  ;  clojure.pprint/pprint)
  (println "Migrations done!"))

(def app
  (handler/site (execute-routing)))

(defn -main [& [port]]
  (let [port (Integer. (or port (System/getenv "PORT")))]
    (jetty/run-jetty (execute-routing)
      {:port port :join? false})))
{'fraction_non_alphanumeric': 0.17013498312710912, 'fraction_numerical': 0.003374578177727784, 'mean_word_length': 3.028312570781427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2881320', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1237, 'n_words': 295}