(ns beherbergung.webserver.handler (:require [compojure.core :refer [defroutes GET POST]] [compojure.route :as route] [ring.util.response :refer [response]] [ring.middleware.cors :refer [wrap-cors]] [beherbergung.webserver.middleware :refer [wrap-graphql wrap-graphiql wrap-nextjs-frontend wrap-frontend-config wrap-defaults]] [beherbergung.resolver.core :refer [graphql]] [beherbergung.config.state :refer [env]])) (def frontend-url (:frontend-base-url env)) (defroutes app-routes (GET "/" [] ;; When using a fullstack-build, this route is overwritten by `wrap-nextjs-frontend` (str "

The backend takes care of data storage and securing its access.
" " It provides a Graphql-API Endpoint.
" " You may want explore the schema and send queries using GraphiQL." "

" "

This build doesn't include the frontend.
" " You may want start it independently and open " frontend-url ".
" " Alternatively production builds including the frontend are available via nix." "

")) (-> (POST "/graphql" req (response (graphql (:body req)))) wrap-graphql wrap-graphiql) (route/not-found "Not Found")) (def app (-> app-routes (wrap-nextjs-frontend) (wrap-frontend-config) (wrap-defaults) (wrap-cors :access-control-allow-origin [#"http://localhost:3000"] :access-control-allow-methods [:get :put :post :delete])))