Move utils that don't really affect implementation to their own module

parent d6bd57b9
#lang racket
(require html-writing
net/url
(require net/url
net/uri-codec
json
web-server/servlet
web-server/servlet-env
web-server/dispatch
racket/runtime-path
magenc/install-factory
magenc/memory-store
magenc/hungry-store
magenc/web-store
magenc/get-put
sql db)
;;; Utilities
;;; =========
;; current working directory... used for serving static content
(define-runtime-path cwd ".")
(define (ok body #:content-type [content-type #"application/octet-stream"])
(response
200 #"OK"
(current-seconds) content-type
'()
(lambda (out-port)
(write-bytes body out-port))))
(define (render-ok sxml)
(ok (xexp->html-bytes sxml)
#:content-type #"text/html"))
(define (not-found)
(response 404 #"Not Found"
(current-seconds) #"text/plain"
'()
(lambda (out-port)
(display #"404 Not Found X_X" out-port))))
(define (json->string json)
(call-with-output-string
(lambda (p)
(write-json json p))))
(define (json->bytes json)
(call-with-output-bytes
(lambda (p)
(write-json json p))))
(define (not-allowed)
(response
405 #"Method Not Allowed"
(current-seconds) #"text/plain"
'()
(lambda (out-port)
(write-bytes #"405 Method Not Allowed :P" out-port))))
sql db
"utils.rkt")
;;; Some parameters
;;; ===============
......
#lang racket
(provide (all-defined-out))
(require json
html-writing
racket/runtime-path
web-server/http/response-structs)
;;; Utilities
;;; =========
;; current working directory... used for serving static content
(define-runtime-path cwd ".")
(define (ok body #:content-type [content-type #"application/octet-stream"])
(response
200 #"OK"
(current-seconds) content-type
'()
(lambda (out-port)
(write-bytes body out-port))))
(define (render-ok sxml)
(ok (xexp->html-bytes sxml)
#:content-type #"text/html"))
(define (not-found)
(response 404 #"Not Found"
(current-seconds) #"text/plain"
'()
(lambda (out-port)
(display #"404 Not Found X_X" out-port))))
(define (json->string json)
(call-with-output-string
(lambda (p)
(write-json json p))))
(define (json->bytes json)
(call-with-output-bytes
(lambda (p)
(write-json json p))))
(define (not-allowed)
(response
405 #"Method Not Allowed"
(current-seconds) #"text/plain"
'()
(lambda (out-port)
(write-bytes #"405 Method Not Allowed :P" out-port))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment