You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

41 lines
1.5 KiB

#lang racket
(require (planet dmac/spin)
web-server/templates
web-server/http
json
redis
"twitter.rkt"
"github.rkt")
(provide start-server)
;; When starting the server, inject, the REDIS client
(define (start-server client #:port [port 8000] #:log-file [log-file "feed.log"])
(get "/"
(lambda (req)
(let ([google-font-link "https://fonts.googleapis.com/css2?family=Amatic+SC&family=Josefin+Sans:ital,wght@1,300&display=swap"]
[tweets/time (get-tweets/redis client #:key "tweet-time:")]
[commits (get-commits/redis client)]
[tweets/score (get-tweets/redis client #:key "tweet-score:")])
(include-template "templates/polling.html"))))
(post "/vote/tweets"
(lambda (req)
(let* ([json/vals (bytes->jsexpr (request-post-data/raw req))]
[tweet-hash (hash-ref json/vals 'hash)]
[vote (hash-ref json/vals 'vote)])
(vote-tweet! client tweet-hash #:upvote? (string=? vote "upvote"))
"OK")))
(post "/vote/commits"
(lambda (req)
(let* ([json/vals (bytes->jsexpr (request-post-data/raw req))]
[commit-hash (hash-ref json/vals 'hash)]
[vote (hash-ref json/vals 'vote)])
(vote-commit! client commit-hash #:upvote? (string=? vote "upvote"))
"OK")))
(displayln (string-append "Running the server on port " (number->string port)))
(run #:port port #:log-file log-file))