0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(core): fix url resolver for cloudflare (#3948)

This commit is contained in:
wangsijie 2023-06-02 11:42:48 +08:00 committed by GitHub
parent 44e18c081a
commit f35d1cbb86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,5 @@
import path from 'node:path';
import { type HostnameProviderData, cloudflareDataGuard } from '@logto/schemas'; import { type HostnameProviderData, cloudflareDataGuard } from '@logto/schemas';
import { got } from 'got'; import { got } from 'got';
@ -17,15 +19,18 @@ export const createCustomHostname = async (auth: HostnameProviderData, hostname:
return mockCustomHostnameResponse(); return mockCustomHostnameResponse();
} }
const response = await got.post(new URL(baseUrl, `/zones/${auth.zoneId}/custom_hostnames`), { const response = await got.post(
headers: { new URL(path.join(baseUrl.pathname, `/zones/${auth.zoneId}/custom_hostnames`), baseUrl),
Authorization: `Bearer ${auth.apiToken}`, {
}, headers: {
json: { Authorization: `Bearer ${auth.apiToken}`,
hostname, },
ssl: { method: 'txt', type: 'dv', settings: { min_tls_version: '1.0' } }, json: {
}, hostname,
}); ssl: { method: 'txt', type: 'dv', settings: { min_tls_version: '1.0' } },
},
}
);
assertThat(response.ok, 'domain.cloudflare_unknown_error'); assertThat(response.ok, 'domain.cloudflare_unknown_error');
@ -47,7 +52,10 @@ export const getCustomHostname = async (auth: HostnameProviderData, identifier:
} }
const response = await got.get( const response = await got.get(
new URL(baseUrl, `/zones/${auth.zoneId}/custom_hostnames/${identifier}`), new URL(
path.join(baseUrl.pathname, `/zones/${auth.zoneId}/custom_hostnames/${identifier}`),
baseUrl
),
{ {
headers: { headers: {
Authorization: `Bearer ${auth.apiToken}`, Authorization: `Bearer ${auth.apiToken}`,