浏览代码

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

master
Christian Fischer 4 个月前
父节点
当前提交
5a477aceeb
共有 3 个文件被更改,包括 17 次插入19 次删除
  1. +5
    -16
      readme.org
  2. +9
    -2
      server/db.rkt
  3. +3
    -1
      server/rest.rkt

+ 5
- 16
readme.org 查看文件

@@ -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 查看文件

@@ -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 查看文件

@@ -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))])


正在加载...
取消
保存