Add addr and port options
README.md
| 14 | 14 | Execute one of the following commands in the root of repository: | |
| 15 | 15 | ||
| 16 | 16 | ``` | |
| 17 | - | guile -L modules --no-auto-compile scripts/pastebin <DATA_DIR> | |
| 18 | - | GUILE_LOAD_PATH=modules GUILE_AUTO_COMPILE=0 scripts/pastebin <DATA_DIR> | |
| 17 | + | guile -L modules --no-auto-compile scripts/pastebin [OPTIONS] <DATA_DIR> | |
| 18 | + | GUILE_LOAD_PATH=modules GUILE_AUTO_COMPILE=0 scripts/pastebin [OPTIONS] <DATA_DIR> | |
| 19 | 19 | ``` | |
| 20 | 20 | ||
| 21 | - | Then navigate your web browser at `http://localhost:8080`. | |
| 21 | + | Then navigate your web browser at `http://localhost:8080`. By default, | |
| 22 | + | pastebin listens on all IPv4 addresses (`0.0.0.0`) and runs on port | |
| 23 | + | `8080`. These can be changed by passing the command line options | |
| 24 | + | `--addr` and `--port`, respectively. | |
| 22 | 25 | ||
| 23 | 26 | `<DATA_DIR>` is a writable filesystem location you want to use to | |
| 24 | - | store pastes. If it doesn't exist, it will be created. | |
| 27 | + | store pastes. If it doesn't exist, it will be created. | |
| 25 | 28 | ||
| 26 | - | It was tested on Guile 2.2.7 and 3.0.7. Many thanks to the Guile | |
| 27 | - | development team for such great software. | |
| 29 | + | It was tested on Guile 3.0.9. Many thanks to the Guile development | |
| 30 | + | team for such great software. | |
| 28 | 31 | ||
| 29 | 32 | ## API | |
| 30 | 33 |
modules/pastebin/main.scm
| 6 | 6 | (define-module (pastebin main)) | |
| 7 | 7 | ||
| 8 | 8 | (use-modules (pastebin httpserver) | |
| 9 | + | (ice-9 getopt-long) | |
| 9 | 10 | (web server)) | |
| 10 | 11 | ||
| 11 | 12 | (export run-pastebin) | |
| 12 | 13 | ||
| 13 | 14 | (define (run-pastebin args) | |
| 14 | - | (let ((data-dir (cadr args))) | |
| 15 | + | (let* ((option-spec '((addr (value #t)) | |
| 16 | + | (port (value #t)))) | |
| 17 | + | (options (getopt-long args option-spec)) | |
| 18 | + | (data-dir (car (option-ref options '() '()))) | |
| 19 | + | (addr-str (option-ref options 'addr "0.0.0.0")) | |
| 20 | + | (port-str (option-ref options 'port "8080"))) | |
| 15 | 21 | (if (not (file-exists? data-dir)) | |
| 16 | 22 | (mkdir data-dir)) | |
| 17 | - | (run-server (make-pastebin-handler data-dir) 'http '(#:addr 0)))) | |
| 23 | + | (run-server (make-pastebin-handler data-dir) 'http | |
| 24 | + | (list #:addr (inet-pton AF_INET addr-str) | |
| 25 | + | #:port (string->number port-str))))) |