about summary refs log tree commit diff
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/webserver.scm31
1 files changed, 15 insertions, 16 deletions
diff --git a/web/webserver.scm b/web/webserver.scm
index 891f4f9..69f5098 100644
--- a/web/webserver.scm
+++ b/web/webserver.scm
@@ -37,11 +37,6 @@
     (if dot-pos
         (substring filename dot-pos) "")))
 
-;; Look into moving this into a config file.
-(define +local-repo-checkout-path+ (getenv "CURRENT_REPO_PATH"))
-(define +remote-repo-url+ (getenv "CGIT_REPO_PATH"))
-(define +working-branch+ (getenv "GN_GUILE_WORKING_BRANCH"))
-
 (define +info+
   `(("name" . "GeneNetwork REST API") ("version" . ,get-version)
     ("comment" . "This is the official REST API for the GeneNetwork service hosted at https://genenetwork.org/")
@@ -235,7 +230,7 @@ otherwise search for set/group data"
              (format #f "The Key  *** ~a *** is missing in your  Json Data"
                      target))))
 
-(define (commit-file-handler repo request body)
+(define (commit-file-handler repo-checkout remote-url request body)
   (catch 'system-error
          (lambda ()
 	   (let* ((post-data (decode-request-json body))
@@ -252,14 +247,14 @@ otherwise search for set/group data"
 	     (build-json-response 200
 				  ((lambda ()
 				     (let ((message
-					    (commit-file +local-repo-checkout-path+
+					    (commit-file repo-checkout
 							 file-name
 							 content
 							 commit-message
 							 username
 							 email
 							 prev-commit)))
-				       (git-invoke +local-repo-checkout-path+ "push" +remote-repo-url+)
+				       (git-invoke repo-checkout "push" remote-url)
 				       message))))))
          (lambda (key . args)
            (let ((msg (car args)))
@@ -275,7 +270,7 @@ otherwise search for set/group data"
 	'application/x-nice-microdata
 	accept)))
 
-(define (controller request body)
+(define (controller request body config)
   (match-lambda
     (('GET)
      (render-json +info+))
@@ -332,9 +327,13 @@ otherwise search for set/group data"
     (('GET "species")
      (render-json (get-species-meta)))
     (('GET "edit")
-     (edit-file-handler +local-repo-checkout-path+ +working-branch+ request))
+     (edit-file-handler (gn-guile-config-gn-docs-local-checkout config)
+                        (gn-guile-config-gn-docs-working-branch config)
+                        request))
     (('POST "commit")
-     (commit-file-handler +local-repo-checkout-path+ request body))
+     (commit-file-handler (gn-guile-config-gn-docs-local-checkout config)
+                          (gn-guile-config-gn-docs-remote-url config)
+                          request body))
     (('GET id)
      (let ((names (get-species-shortnames (get-expanded-species))))
        (match (string->list id)
@@ -373,16 +372,16 @@ otherwise search for set/group data"
 (define (request-path-components request)
   (split-and-decode-uri-path (uri-path (request-uri request))))
 
-(define (handler request body)
+(define (handler request body config)
   (format #t "~a ~a\n"
           (request-method request)
           (uri-path (request-uri request)))
   (apply values
-         ((controller request body)
+         ((controller request body config)
           (cons (request-method request)
                 (request-path-components request)))))
 
-(define (start-web-server address port)
+(define (start-web-server address port config)
   (format (current-error-port)
           "GN REST API web server listening on http://~a:~a/~%" address port)
   ;; Wrap handler in another function to support live hacking via the
@@ -390,7 +389,7 @@ otherwise search for set/group data"
   ;; REPL, the web server will still be using the old handler. The
   ;; only way to update the handler reference held by the web server
   ;; would be to restart the web server.
-  (run-server (cut handler <> <>)
+  (run-server (cut handler <> <> config)
               'http
               (list #:addr (inet-pton AF_INET address)
                     #:port port)))
@@ -404,4 +403,4 @@ otherwise search for set/group data"
     (when (option-ref options 'write)
       (options-write options))
     (display `("listening on" ,listen))
-    (start-web-server "127.0.0.1" listen)))
+    (start-web-server "127.0.0.1" listen (cli-options->gn-guile-config options))))