|
13 | 13 |
|
14 | 14 | ;; const path = require("path");
|
15 | 15 | (define path ($/require "path"))
|
16 |
| -(define url ($/require "url")) |
17 | 16 |
|
18 |
| -;; __dirname doesnt work in ES6 |
| 17 | +;; __dirname doesnt work in ES6, so use workaround |
| 18 | +(define url ($/require "url")) |
19 | 19 | (define __dirname
|
20 | 20 | (#js.path.dirname (#js.url.fileURLToPath #js*.import.meta.url)))
|
21 | 21 |
|
|
37 | 37 | (define fastify-static ($/require "fastify-static"))
|
38 | 38 | (#js.fastify.register
|
39 | 39 | 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")] |
42 | 41 | [prefix #js"/"]}) ;; optional: default '/'
|
43 | 42 |
|
44 | 43 | ;; // fastify-formbody lets us parse incoming forms
|
|
99 | 98 | ;; reply.view("/src/pages/index.hbs", params);
|
100 | 99 | ;; });
|
101 | 100 | (define colors ($/require "./src/colors.json"))
|
| 101 | + |
102 | 102 | (define (handle-get request reply)
|
103 | 103 | (define params
|
104 | 104 | (if ($/defined? #js.request.query.randomize)
|
|
110 | 110 | [seo seo]})
|
111 | 111 | {$/obj [seo seo]}))
|
112 | 112 | (#js.reply.view #js"/src/pages/index.hbs" params))
|
| 113 | + |
113 | 114 | (#js.fastify.get #js"/" handle-get)
|
114 | 115 |
|
115 | 116 |
|
|
162 | 163 | (define req-color #js.request.body.color)
|
163 | 164 | (define params
|
164 | 165 | (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]})) |
174 | 174 | {$/obj [seo seo]}))
|
175 | 175 | (#js.reply.view #js"/src/pages/index.hbs" params))
|
| 176 | + |
176 | 177 | (#js.fastify.post #js"/" handle-post)
|
177 | 178 |
|
178 | 179 | ;; // Run the server and report out to the logs
|
|
185 | 186 | ;; fastify.log.info(`server listening on ${address}`);
|
186 | 187 | ;; });
|
187 | 188 | (define (handle-listen err address)
|
188 |
| - (if ($/binop === err $/null) |
| 189 | + (unless ($/null? err) |
189 | 190 | (#js.fastify.log.error err)
|
190 | 191 | (#js.process.exit 1))
|
191 | 192 | (#js.console.log ($/+ #js"Your app is listening on " address))
|
192 | 193 | (#js.fastify.log.info ($/+ #js"server listening on " address)))
|
| 194 | + |
193 | 195 | (#js.fastify.listen PORT #js"0.0.0.0" handle-listen)
|
0 commit comments