Quellcode durchsuchen

Configure SQL info, and API listening port, with env. variables

master
Christian Fischer vor 4 Monaten
Ursprung
Commit
5a477aceeb
3 geänderte Dateien mit 17 neuen und 19 gelöschten Zeilen
  1. +5
    -16
      readme.org
  2. +9
    -2
      server/db.rkt
  3. +3
    -1
      server/rest.rkt

+ 5
- 16
readme.org Datei anzeigen

@@ -11,26 +11,15 @@ cd gn-proxy
raco pkg install
#+end_src

The REST server can then be started by running server/rest.rkt:
The REST server can then be started by running server/rest.rkt, while
providing the SQL username and password as environment variables:

#+begin_src bash
racket server/rest.rkt
env SQL_USER=username SQL_PASSWORD=password racket server/rest.rkt
#+end_src

By default it listens on port 8080 and listens on 127.0.0.1, which
can be changed in ~server/rest.rkt~:

#+begin_src racket
(define stop
(serve
#:dispatch (sequencer:make
(filter:make #rx"^/available/"
query-available-dispatcher)
(filter:make #rx"^/run-action/"
run-action-dispatcher))
#:listen-ip "127.0.0.1"
#:port 8080))
#+end_src
By default it listens on port 8080 and listens on 127.0.0.1, however
the port can be changed with the PORT environment variable.

The Redis and MariaDB connections are handled in ~server/db.rkt~, and
can be configured by editing ~connect-redis~ and ~connect-sql~. See the


+ 9
- 2
server/db.rkt Datei anzeigen

@@ -8,15 +8,22 @@
redis-conn
mysql-conn)


;; This should be a racket parameter
(define (connect-redis)
(make-redis))

(define redis-conn (make-parameter (connect-redis)))

(define sql-user (getenv "SQL_USER"))
(define sql-pass (getenv "SQL_PASSWORD"))

(unless (and sql-user sql-pass)
(error "provide SQL user information with SQL_USER and SQL_PASSWORD environment variables"))

(define (connect-sql)
(mysql-connect #:user "gn2"
#:password "gn2"
(mysql-connect #:user sql-user
#:password sql-pass
#:database "db_webqtl_s"))

(define mysql-conn (make-parameter (connect-sql)))

+ 3
- 1
server/rest.rkt Datei anzeigen

@@ -116,7 +116,9 @@
(filter:make #rx"^/run-action/"
run-action-dispatcher))
#:listen-ip "127.0.0.1"
#:port 8080))
#:port (string->number
(or (getenv "PORT")
"8080"))))

(with-handlers ([exn:break? (lambda (e)
(stop))])


Laden…
Abbrechen
Speichern