Skip to content

Commit 4c4504e

Browse files
committed
refactor: migrate from nginx static site to Racket web server
1 parent 659744a commit 4c4504e

3 files changed

Lines changed: 49 additions & 7 deletions

File tree

Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
FROM nginx:alpine
1+
# Use the official Racket image
2+
FROM racket/racket:latest
23

3-
# Copy your static HTML into nginx's default public directory
4-
COPY index.html /usr/share/nginx/html/
4+
WORKDIR /app
55

6-
# Expose nginx default port
7-
EXPOSE 80
6+
COPY server.rkt .
7+
COPY public ./public
88

9-
# Start nginx
10-
CMD ["nginx", "-g", "daemon off;"]
9+
EXPOSE 8000
1110

11+
CMD ["racket", "server.rkt"]
File renamed without changes.

server.rkt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#lang racket
2+
3+
(require web-server/web-server
4+
web-server/servlet-env
5+
web-server/http/request-structs
6+
web-server/http/response-structs
7+
net/url
8+
racket/runtime-path
9+
racket/base
10+
racket/file)
11+
12+
;; Serve ./public (with index.html as default)
13+
(define-runtime-path PUBLIC_DIR "public")
14+
15+
(define PORT 8000)
16+
17+
;; Simple request handler that serves static files
18+
(define (my-handler req)
19+
(define uri (request-uri req))
20+
(define path-parts (url-path uri))
21+
(define path-string
22+
(if (null? path-parts)
23+
"/"
24+
(string-append "/" (string-join (map path/param-path path-parts) "/"))))
25+
(define file-path
26+
(cond
27+
[(or (string=? path-string "/") (string=? path-string ""))
28+
(build-path PUBLIC_DIR "index.html")]
29+
[else
30+
(build-path PUBLIC_DIR (substring path-string 1))]))
31+
32+
(if (file-exists? file-path)
33+
(response/full 200 #"OK" (current-seconds) #"text/html" '()
34+
(list (file->bytes file-path)))
35+
(response/full 404 #"Not Found" (current-seconds) #"text/plain" '()
36+
(list #"File not found"))))
37+
38+
(serve/servlet my-handler
39+
#:port PORT
40+
#:listen-ip #f
41+
#:servlet-path "/"
42+
#:servlet-regexp #rx"")

0 commit comments

Comments
 (0)