Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router serving static-file only works locally #254

Open
BuddhiLW opened this issue Nov 21, 2022 · 6 comments
Open

Router serving static-file only works locally #254

BuddhiLW opened this issue Nov 21, 2022 · 6 comments

Comments

@BuddhiLW
Copy link

I want to create a router for <website.com>/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

  • I tried prefixing, and creating a different end-point for each. So, public/pdf/.pdf, /pdf/.pfg, .pdf.
  • I tried copying the file in all possible directories, public/pdf, root, or content/pdf.
  • Using only (path "<path>.pdf") and dropping the (let [config (resolve-config)] ...)` stuff

None worked.

@yogthos
Copy link
Member

yogthos commented Nov 21, 2022

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

@BuddhiLW
Copy link
Author

(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
Copy link
Author

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

But, not on the deployed website.

@BuddhiLW
Copy link
Author

maim-HDMI-1-0-20221121-190241

@yogthos
Copy link
Member

yogthos commented Nov 21, 2022

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
Copy link
Author

BuddhiLW commented Jan 1, 2023

I see.

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

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants