Trying to query an endpoint which enforces ssl on locahost:8000 (or 0.0.0.0:8000, or 127.0.0.1:8000) causes urql to error:
cause: [Error: 0088E6AB85140000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:354:
] {
library: 'SSL routines',
reason: 'wrong version number',
code: 'ERR_SSL_WRONG_VERSION_NUMBER'
}
},
This request appears like so on my Saleor api endpoint: api_1 | [2024-02-02 10:59:27 +0000] [25] [WARNING] Invalid HTTP request received.
I'm using Astrojs + urql/core.
I have a nanostore for my urql client, which I initialise like so:
connect.ts
export function connect(options?: { api_url?: string, token?: Token }): Client {
const client = new Client({
url: options?.api_url || import.meta.env.PUBLIC_GRAPHQL_URL,
exchanges: [retryExchange({ initialDelayMs: 100, maxNumberAttempts: 5 }), fetchExchange],
requestPolicy: "network-only",
fetchOptions: () => {
if (options?.token) {
return {
headers: { authorization: options.token ? `Bearer ${options.token}` : "" }
}
}
else return {}
}
})
return client
}
server-client.ts
import { connect } from "#scripts/connect";
export let _gql_client = map(connect())
Then use like so in my SSR astro pages:
pages/index.astro
---
import { _gql_client } from "#stores/server-client"
let { product: product_slug } = Astro.params
const product_result = await _gql_client
.get()
.query<ProductDetailsQuery, ProductDetailsQueryVariables>(query_product_details, { slug: product_slug!, channel: default_channel })
const product = product_result.data?.product
const name = parse_pretty_text(product?.name)
---
<h1 set:html={name} />
.
.
.