Skip to content

Commit 1f7696b

Browse files
committed
cleanup
1 parent 972845b commit 1f7696b

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

server.rkt

+16-14
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
;; const path = require("path");
1515
(define path ($/require "path"))
16-
(define url ($/require "url"))
1716

18-
;; __dirname doesnt work in ES6
17+
;; __dirname doesnt work in ES6, so use workaround
18+
(define url ($/require "url"))
1919
(define __dirname
2020
(#js.path.dirname (#js.url.fileURLToPath #js*.import.meta.url)))
2121

@@ -37,8 +37,7 @@
3737
(define fastify-static ($/require "fastify-static"))
3838
(#js.fastify.register
3939
fastify-static
40-
{$/obj ;[root #js"./public"]
41-
[root (#js.path.join #js.__dirname #js"public")]
40+
{$/obj [root (#js.path.join #js.__dirname #js"public")]
4241
[prefix #js"/"]}) ;; optional: default '/'
4342

4443
;; // fastify-formbody lets us parse incoming forms
@@ -99,6 +98,7 @@
9998
;; reply.view("/src/pages/index.hbs", params);
10099
;; });
101100
(define colors ($/require "./src/colors.json"))
101+
102102
(define (handle-get request reply)
103103
(define params
104104
(if ($/defined? #js.request.query.randomize)
@@ -110,6 +110,7 @@
110110
[seo seo]})
111111
{$/obj [seo seo]}))
112112
(#js.reply.view #js"/src/pages/index.hbs" params))
113+
113114
(#js.fastify.get #js"/" handle-get)
114115

115116

@@ -162,17 +163,17 @@
162163
(define req-color #js.request.body.color)
163164
(define params
164165
(if ($/defined? req-color)
165-
(let* ([color-lower (#js.req-color.toLowerCase)]
166-
[color (#js.color-lower.trim)])
167-
(if ($/defined? ($ colors color))
168-
;; Found one!
169-
{$/obj [color ($ colors color)]
170-
[colorError $/null]
171-
[seo seo]}
172-
{$/obj [colorError req-color]
173-
[seo seo]}))
166+
(let ([color ($> (#js.req-color.toLowerCase) (trim))])
167+
(if ($/defined? ($ colors color))
168+
;; Found one!
169+
{$/obj [color ($ colors color)]
170+
[colorError $/null]
171+
[seo seo]}
172+
{$/obj [colorError req-color]
173+
[seo seo]}))
174174
{$/obj [seo seo]}))
175175
(#js.reply.view #js"/src/pages/index.hbs" params))
176+
176177
(#js.fastify.post #js"/" handle-post)
177178

178179
;; // Run the server and report out to the logs
@@ -185,9 +186,10 @@
185186
;; fastify.log.info(`server listening on ${address}`);
186187
;; });
187188
(define (handle-listen err address)
188-
(if ($/binop === err $/null)
189+
(unless ($/null? err)
189190
(#js.fastify.log.error err)
190191
(#js.process.exit 1))
191192
(#js.console.log ($/+ #js"Your app is listening on " address))
192193
(#js.fastify.log.info ($/+ #js"server listening on " address)))
194+
193195
(#js.fastify.listen PORT #js"0.0.0.0" handle-listen)

0 commit comments

Comments
 (0)