cryogen-project / cryogen

A simple static site generator written in Clojure
http://cryogenweb.org/
Eclipse Public License 1.0
1.1k stars 96 forks source link

Router serving static-file only works locally #254

Open BuddhiLW opened 2 years ago

BuddhiLW commented 2 years ago

I want to create a router for /cv1 and serve a pdf.

Locally, it works just fine. That is, curl will work. And, the page renders a pdf on the browser.

Locally: maim-region-20221121-180237

But, in my website, it gives 404, www.buddhilw.com/cv1.

In the server.clj, I defined the router cv1, as so:

(defroutes routes
  (GET "/" [] (redirect
               (let [config (resolve-config)]
                 (path (:blog-prefix config)
                       (when (= (:clean-urls config) :dirty)
                         "index.html")))))
  (GET "/cv1" [] (ring.util.response/file-response
                              (let [config (resolve-config)]
                                  (path (:blog-prefix config)
                                             "cv-2022-11-03.pdf"))))
  (route/files "/")
  (route/not-found "Page not found"))

What could I do to accomplish the file-serving?

What I have tried

None worked.

yogthos commented 2 years ago

You should just be able to serve the PDF as a resource from the public folder.

BuddhiLW commented 2 years ago
(defroutes routes
  (GET "/" [] (redirect
               (let [config (resolve-config)]
                 (path (:blog-prefix config)
                       (when (= (:clean-urls config) :dirty)
                         "index.html")))))
  (GET "/cv1" [] (ring.util.response/file-response
                  (path
                   "public/pdf/cv-2022-11-03.pdf")))
  (GET "/cv2" [] (ring.util.response/file-response
                  (path
                   "pdf/cv-2022-11-03.pdf")))
  (GET "/cv3" [] (ring.util.response/file-response
                  (path "cv-2022-11-03.pdf")))
$ tree public/pdf/
public/pdf/
├── cv-2021-08-11.pdf
└── cv-2022-11-03.pdf

0 directories, 2 files

This doesn't work. None of the three end-points. I don't know what to try further.

BuddhiLW commented 2 years ago

Oh, yeah, if I run lein serve, it works on localhost:3000/v1 and v3.

But, not on the deployed website.

BuddhiLW commented 2 years ago

maim-HDMI-1-0-20221121-190241

yogthos commented 2 years ago

The problem there is that you won't have a server running once you build the site. You'd have to link to the PDF file from the page relative to your public folder.

BuddhiLW commented 1 year ago

I see.

Could you give me an example, or a direction, of how I may achieve that? I have no idea.

Thanks in advance.