Last active
January 19, 2024 15:20
-
-
Save RyanKung/5058726 to your computer and use it in GitHub Desktop.
Demo: A simple MVC-web-framework implementation with PLT Scheme (Racket)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;By Jhen Kung, [email protected] | |
;;app.rkt | |
#lang racket(require web-server/servlet | |
web-server/servlet-env | |
"router.rkt") | |
(serve/servlet mordor | |
#:port 8080 | |
#:servlet-path "/" | |
#:servlet-regexp #rx"") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;By Jhen Kung, [email protected] | |
;;model.rkt | |
(require db) | |
(define connect | |
(mysql-connect #:user user | |
#:database db | |
#:password password)) | |
(query-exec connect | |
"create temporary table the_numbers (n integer, d varchar(20))") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;By Jhen Kung, [email protected] | |
;;router.rkt | |
(module router racket | |
(require web-server/servlet | |
web-server/servlet-env | |
"view.rkt") | |
(define-values (dispatch req-url) | |
;;router | |
(dispatch-rules | |
[("") test] | |
[("test") index] | |
[else index])) | |
(define (mordor req) | |
(dispatch req)) | |
(provide mordor)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;By Jhen Kung, [email protected] | |
;;view.rkt | |
(module view racket | |
(require web-server/servlet | |
web-server/servlet-env | |
web-server/templates) | |
(define (index req) | |
(response/xexpr | |
`(html (head (title ,(url->string (request-uri req)))) | |
(body (h1 "PINTOV!") | |
(span ,(url->string (request-uri req))) | |
)))) | |
(define (test req) | |
(response/full | |
200 #"Okay" | |
(current-seconds) TEXT/HTML-MIME-TYPE | |
empty | |
(list (string->bytes/utf-8 (include-template "index.html"))))) | |
(provide index test)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment