4

Clojure を使用して lacinia-pedestal graphql サーバーをセットアップし、apollo を使用してクライアント側の JavaScript コードでアクセスしようとしています。ただし、COR で許可されていない localhost オリジン (localhost:3000) からアクセスしようとしているため、localhost の /graphql エンドポイントにアクセスできません。lacinia-pedestal を使用して COR を設定するにはどうすればよいですか?

サーバー側のコードは次のとおりです (lacinia チュートリアルhttps://lacinia.readthedocs.io/en/latest/tutorial/component.htmlを使用してセットアップ)

(ns project.server
  (:require [com.stuartsierra.component :as component]
            [com.walmartlabs.lacinia.pedestal :as lp]
            [io.pedestal.http :as http]))

(defrecord Server [schema-provider server]

  component/Lifecycle

  (start [this]
    (assoc this :server (-> schema-provider
                            :schema
                            (lp/service-map {:graphiql true})
                            http/create-server
                            http/start)))

  (stop [this]
    (http/stop server)
    (assoc this :server nil)))

(defn new-server
  []
  {:server (-> {}
               map->Server
               (component/using [:schema-provider]))})

クライアント側のコードは非常にシンプルです (Apollo を使用):

const client = new ApolloClient({
  uri: "http://localhost:8888/graphql"
});
4

1 に答える 1