diff --git a/src/main/backend/handlers.clj b/src/main/backend/handlers.clj index 57d9de2..2eeb71b 100644 --- a/src/main/backend/handlers.clj +++ b/src/main/backend/handlers.clj @@ -50,7 +50,7 @@ (apply str (mapv build-catalog-item catalog)))) (defn process-hu-post - [page {:keys [content-type replace-str wrap-fn]}] + [page {:keys [resp-headers replace-str wrap-fn]}] (let [post-content (.getElementsByClass page "Post-RichTextContainer") title (.getElementsByClass page "Post-Title") post-time (.getElementsByClass page "ContentItem-time")] @@ -60,7 +60,7 @@ (render-linkcard post-content) {:status 200 - :headers content-type + :headers resp-headers :body (wrap-fn {:content (.toString post-content) :title (.text title) @@ -74,7 +74,7 @@ docs (.getElementsByClass page "Post-RichTextContainer")] (if (empty? docs) {:status 404 - :headers (:content-type params) + :headers (:resp-headers params) :body (wrap-json {:content "Not Found" :title "Not Found"})} (process-hu-post page params)))) @@ -89,7 +89,8 @@ [request] (let [post-id (-> request :path-params :id)] (fetch-hu-post post-id - {:content-type {"Content-Type" "application/json; charset=utf-8"} + {:resp-headers {"Content-Type" "application/json; charset=utf-8" + "Access-Control-Allow-Origin" "*"} :replace-str "#/hp/" :wrap-fn wrap-json}))) @@ -129,9 +130,9 @@ :updated_time (get m "updatedTime")})) (defn process-hu-questiion - [question-json {:keys [content-type wrap-fn]}] + [question-json {:keys [resp-headers wrap-fn]}] {:status 200 - :headers content-type + :headers resp-headers :body (wrap-fn question-json)}) (defn fetch-hu-answers @@ -195,7 +196,7 @@ question-error? (= (get question-json "subAppName") "errorpage")] (if question-error? {:status 404 - :headers (:content-type params) + :headers (:resp-headers params) :body (wrap-json {:content "Not Found" :title "Not Found"})} (if (empty? query) @@ -213,5 +214,6 @@ [request] (fetch-hu-question request - {:content-type {"Content-Type" "application/json; charset=utf-8"} + {:resp-headers {"Content-Type" "application/json; charset=utf-8" + "Access-Control-Allow-Origin" "*"} :wrap-fn wrap-json})) diff --git a/src/main/backend/hugo/site.clj b/src/main/backend/hugo/site.clj index 462f882..f5e8ace 100644 --- a/src/main/backend/hugo/site.clj +++ b/src/main/backend/hugo/site.clj @@ -29,6 +29,7 @@ (let [post-id (-> request :path-params :id)] (handlers/fetch-hu-post post-id - {:content-type {"Content-Type" "text/html; charset=utf-8"} + {:resp-headers {"Content-Type" "text/html; charset=utf-8" + "Access-Control-Allow-Origin" "*"} :replace-str "/hp/" :wrap-fn hugo-post-template})))