chore: change URL construction
This commit is contained in:
5
.changeset/khaki-seahorses-tell.md
Normal file
5
.changeset/khaki-seahorses-tell.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@nhost/dashboard': patch
|
||||
---
|
||||
|
||||
chore(projects): change the way how API URLs are constructed
|
||||
@@ -33,7 +33,7 @@ export function HasuraData({ close }: HasuraDataProps) {
|
||||
? `${getHasuraConsoleServiceUrl()}`
|
||||
: generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
defaultLocalBackendSlugs,
|
||||
{ ...defaultRemoteBackendSlugs, hasura: '/console' },
|
||||
|
||||
@@ -194,7 +194,7 @@ export default function RuleGroupEditor({
|
||||
<Link
|
||||
href={`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region?.awsName,
|
||||
currentProject.region,
|
||||
'hasura',
|
||||
)}/console/data/default/schema/${schema}/tables/${table}/permissions`}
|
||||
underline="hover"
|
||||
|
||||
@@ -107,7 +107,7 @@ export default function SystemEnvironmentVariableSettings() {
|
||||
? `${getHasuraConsoleServiceUrl()}/console`
|
||||
: generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
defaultLocalBackendSlugs,
|
||||
{ ...defaultRemoteBackendSlugs, hasura: '/console' },
|
||||
|
||||
@@ -217,7 +217,7 @@ export default function AppleProviderSettings() {
|
||||
id="redirectUrl"
|
||||
defaultValue={`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/apple/callback`}
|
||||
className="col-span-2"
|
||||
@@ -236,7 +236,7 @@ export default function AppleProviderSettings() {
|
||||
copy(
|
||||
`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/apple/callback`,
|
||||
'Redirect URL',
|
||||
|
||||
@@ -163,7 +163,7 @@ export default function AzureADProviderSettings() {
|
||||
id="redirectUrl"
|
||||
defaultValue={`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/azuread/callback`}
|
||||
className="col-span-2"
|
||||
@@ -182,7 +182,7 @@ export default function AzureADProviderSettings() {
|
||||
copy(
|
||||
`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/azuread/callback`,
|
||||
'Redirect URL',
|
||||
|
||||
@@ -139,7 +139,7 @@ export default function DiscordProviderSettings() {
|
||||
label="Redirect URL"
|
||||
defaultValue={`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/discord/callback`}
|
||||
disabled
|
||||
@@ -154,7 +154,7 @@ export default function DiscordProviderSettings() {
|
||||
copy(
|
||||
`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/discord/callback`,
|
||||
'Redirect URL',
|
||||
|
||||
@@ -139,7 +139,7 @@ export default function FacebookProviderSettings() {
|
||||
label="Redirect URL"
|
||||
defaultValue={`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/facebook/callback`}
|
||||
disabled
|
||||
@@ -154,7 +154,7 @@ export default function FacebookProviderSettings() {
|
||||
copy(
|
||||
`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/facebook/callback`,
|
||||
'Redirect URL',
|
||||
|
||||
@@ -145,7 +145,7 @@ export default function GitHubProviderSettings() {
|
||||
label="Redirect URL"
|
||||
defaultValue={`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/github/callback`}
|
||||
disabled
|
||||
@@ -160,7 +160,7 @@ export default function GitHubProviderSettings() {
|
||||
copy(
|
||||
`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/github/callback`,
|
||||
'Redirect URL',
|
||||
|
||||
@@ -139,7 +139,7 @@ export default function GoogleProviderSettings() {
|
||||
label="Redirect URL"
|
||||
defaultValue={`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/google/callback`}
|
||||
disabled
|
||||
@@ -154,7 +154,7 @@ export default function GoogleProviderSettings() {
|
||||
copy(
|
||||
`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/google/callback`,
|
||||
'Redirect URL',
|
||||
|
||||
@@ -139,7 +139,7 @@ export default function LinkedInProviderSettings() {
|
||||
label="Redirect URL"
|
||||
defaultValue={`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/linkedin/callback`}
|
||||
disabled
|
||||
@@ -154,7 +154,7 @@ export default function LinkedInProviderSettings() {
|
||||
copy(
|
||||
`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/linkedin/callback`,
|
||||
'Redirect URL',
|
||||
|
||||
@@ -139,7 +139,7 @@ export default function SpotifyProviderSettings() {
|
||||
label="Redirect URL"
|
||||
defaultValue={`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/spotify/callback`}
|
||||
disabled
|
||||
@@ -154,7 +154,7 @@ export default function SpotifyProviderSettings() {
|
||||
copy(
|
||||
`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/spotify/callback`,
|
||||
'Redirect URL',
|
||||
|
||||
@@ -145,7 +145,7 @@ export default function TwitchProviderSettings() {
|
||||
label="Redirect URL"
|
||||
defaultValue={`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/twitch/callback`}
|
||||
disabled
|
||||
@@ -160,7 +160,7 @@ export default function TwitchProviderSettings() {
|
||||
copy(
|
||||
`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/twitch/callback`,
|
||||
'Redirect URL',
|
||||
|
||||
@@ -167,7 +167,7 @@ export default function TwitterProviderSettings() {
|
||||
id="redirectUrl"
|
||||
defaultValue={`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/twitter/callback`}
|
||||
className="col-span-2"
|
||||
@@ -186,7 +186,7 @@ export default function TwitterProviderSettings() {
|
||||
copy(
|
||||
`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/twitter/callback`,
|
||||
'Redirect URL',
|
||||
|
||||
@@ -138,7 +138,7 @@ export default function WindowsLiveProviderSettings() {
|
||||
label="Redirect URL"
|
||||
defaultValue={`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/windowslive/callback`}
|
||||
disabled
|
||||
@@ -153,7 +153,7 @@ export default function WindowsLiveProviderSettings() {
|
||||
copy(
|
||||
`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/windowslive/callback`,
|
||||
'Redirect URL',
|
||||
|
||||
@@ -184,7 +184,7 @@ export default function WorkOsProviderSettings() {
|
||||
id="redirectUrl"
|
||||
defaultValue={`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/workos/callback`}
|
||||
className="col-span-2"
|
||||
@@ -203,7 +203,7 @@ export default function WorkOsProviderSettings() {
|
||||
copy(
|
||||
`${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
)}/signin/provider/workos/callback`,
|
||||
'Redirect URL',
|
||||
|
||||
@@ -68,7 +68,7 @@ export default function CreateUserForm({
|
||||
|
||||
const baseAuthUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region?.awsName,
|
||||
currentProject?.region,
|
||||
'auth',
|
||||
);
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ fragment Project on apps {
|
||||
id
|
||||
countryCode
|
||||
awsName
|
||||
domain
|
||||
city
|
||||
}
|
||||
plan {
|
||||
|
||||
@@ -12,7 +12,7 @@ export default function useIsHealthy() {
|
||||
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region?.awsName,
|
||||
currentProject?.region,
|
||||
'auth',
|
||||
);
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ export default function useCreateColumnMutation({
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
const mutationFn = isPlatform ? createColumn : createColumnMigration;
|
||||
|
||||
@@ -43,7 +43,7 @@ export default function useCreateRecordMutation<TData extends object = {}>({
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ export default function useCreateTableMutation({
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
const mutationFn = isPlatform ? createTable : createTableMigration;
|
||||
|
||||
@@ -41,7 +41,7 @@ export default function useDatabaseQuery(
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ export default function useDeleteColumnMutation({
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
const mutationFn = isPlatform ? deleteColumn : deleteColumnMigration;
|
||||
|
||||
@@ -39,7 +39,7 @@ export default function useDeleteRecordMutation({
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ export default function useDeleteTableMutation({
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
const mutationFn = isPlatform ? deleteTable : deleteTableMigration;
|
||||
|
||||
@@ -44,7 +44,7 @@ export default function useManagePermissionMutation({
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ export default function useMetadataQuery(
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ export default function useTableQuery(
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ export default function useTrackForeignKeyRelationMutation({
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
const mutationFn = isPlatform
|
||||
|
||||
@@ -37,7 +37,7 @@ export default function useTrackTableMutation({
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
const mutationFn = isPlatform ? trackTable : trackTableMigration;
|
||||
|
||||
@@ -42,7 +42,7 @@ export default function useUpdateColumnMutation({
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
const mutationFn = isPlatform ? updateColumn : updateColumnMigration;
|
||||
|
||||
@@ -43,7 +43,7 @@ export default function useUpdateRecordMutation<TData extends object = {}>({
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ export default function useUpdateTableMutation({
|
||||
const { currentProject } = useCurrentWorkspaceAndProject();
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'hasura',
|
||||
);
|
||||
const mutationFn = isPlatform ? updateTable : updateTableMigration;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { useCurrentWorkspaceAndProject } from '@/features/projects/common/hooks/useCurrentWorkspaceAndProject';
|
||||
import useIsPlatform from '@/hooks/common/useIsPlatform';
|
||||
import generateAppServiceUrl from '@/utils/common/generateAppServiceUrl/generateAppServiceUrl';
|
||||
import {
|
||||
getAuthServiceUrl,
|
||||
getFunctionsServiceUrl,
|
||||
getGraphqlServiceUrl,
|
||||
getStorageServiceUrl,
|
||||
} from '@/utils/env';
|
||||
import { isDevOrStaging } from '@/utils/helpers';
|
||||
import type { NhostNextClientConstructorParams } from '@nhost/nextjs';
|
||||
import { NhostClient } from '@nhost/nextjs';
|
||||
|
||||
@@ -43,11 +43,32 @@ export function useAppClient(
|
||||
});
|
||||
}
|
||||
|
||||
const authUrl = generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region,
|
||||
'auth',
|
||||
);
|
||||
const graphqlUrl = generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region,
|
||||
'graphql',
|
||||
);
|
||||
const storageUrl = generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region,
|
||||
'storage',
|
||||
);
|
||||
const functionsUrl = generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region,
|
||||
'functions',
|
||||
);
|
||||
|
||||
return new NhostClient({
|
||||
subdomain: currentProject.subdomain,
|
||||
region: isDevOrStaging()
|
||||
? `${currentProject.region.awsName}.staging`
|
||||
: currentProject.region.awsName,
|
||||
authUrl,
|
||||
graphqlUrl,
|
||||
storageUrl,
|
||||
functionsUrl,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ export default function useFiles({
|
||||
) => {
|
||||
const fetchUrl = `${generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'storage',
|
||||
)}/files/${file.id}`;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ export function useRemoteApplicationGQLClient() {
|
||||
link: new HttpLink({
|
||||
uri: generateAppServiceUrl(
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
'graphql',
|
||||
),
|
||||
headers: {
|
||||
@@ -35,7 +35,7 @@ export function useRemoteApplicationGQLClient() {
|
||||
}, [
|
||||
loading,
|
||||
currentProject?.subdomain,
|
||||
currentProject?.region.awsName,
|
||||
currentProject?.region,
|
||||
currentProject?.config?.hasura.adminSecret,
|
||||
]);
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ export default function GraphQLPage() {
|
||||
|
||||
const appUrl = generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'graphql',
|
||||
);
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ export default function MetricsPage() {
|
||||
<Button
|
||||
href={generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'grafana',
|
||||
)}
|
||||
// Both `target` and `rel` are available when `href` is set. This is
|
||||
|
||||
@@ -19,7 +19,7 @@ export default function StoragePage() {
|
||||
<NhostApolloProvider
|
||||
graphqlUrl={generateAppServiceUrl(
|
||||
currentProject.subdomain,
|
||||
currentProject.region.awsName,
|
||||
currentProject.region,
|
||||
'graphql',
|
||||
)}
|
||||
fetchPolicy="cache-first"
|
||||
|
||||
926
dashboard/src/utils/__generated__/graphql.ts
generated
926
dashboard/src/utils/__generated__/graphql.ts
generated
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,4 @@
|
||||
import type { ProjectFragment } from '@/utils/__generated__/graphql';
|
||||
import { test, vi } from 'vitest';
|
||||
import generateAppServiceUrl, {
|
||||
defaultLocalBackendSlugs,
|
||||
@@ -29,31 +30,41 @@ afterEach(() => {
|
||||
process.env = { ...env };
|
||||
});
|
||||
|
||||
const region: ProjectFragment['region'] = {
|
||||
id: '1',
|
||||
awsName: 'eu-west-1',
|
||||
domain: 'nhost.run',
|
||||
city: 'Dublin',
|
||||
countryCode: 'IE',
|
||||
};
|
||||
|
||||
const stagingRegion = { ...region, domain: 'staging.nhost.run' };
|
||||
|
||||
test('should generate a per service subdomain in remote mode', () => {
|
||||
process.env.NEXT_PUBLIC_NHOST_PLATFORM = 'true';
|
||||
process.env.NEXT_PUBLIC_ENV = 'production';
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'auth')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'auth')).toBe(
|
||||
'https://test.auth.eu-west-1.nhost.run/v1',
|
||||
);
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'functions')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'functions')).toBe(
|
||||
'https://test.functions.eu-west-1.nhost.run/v1',
|
||||
);
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'graphql')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'graphql')).toBe(
|
||||
'https://test.graphql.eu-west-1.nhost.run/v1',
|
||||
);
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'storage')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'storage')).toBe(
|
||||
'https://test.storage.eu-west-1.nhost.run/v1',
|
||||
);
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'hasura')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'hasura')).toBe(
|
||||
'https://test.hasura.eu-west-1.nhost.run',
|
||||
);
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'grafana')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'grafana')).toBe(
|
||||
'https://test.grafana.eu-west-1.nhost.run',
|
||||
);
|
||||
});
|
||||
@@ -62,54 +73,54 @@ test('should generate staging subdomains in staging environment', () => {
|
||||
process.env.NEXT_PUBLIC_NHOST_PLATFORM = 'true';
|
||||
process.env.NEXT_PUBLIC_ENV = 'staging';
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'auth')).toBe(
|
||||
expect(generateAppServiceUrl('test', stagingRegion, 'auth')).toBe(
|
||||
'https://test.auth.eu-west-1.staging.nhost.run/v1',
|
||||
);
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'functions')).toBe(
|
||||
expect(generateAppServiceUrl('test', stagingRegion, 'functions')).toBe(
|
||||
'https://test.functions.eu-west-1.staging.nhost.run/v1',
|
||||
);
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'graphql')).toBe(
|
||||
expect(generateAppServiceUrl('test', stagingRegion, 'graphql')).toBe(
|
||||
'https://test.graphql.eu-west-1.staging.nhost.run/v1',
|
||||
);
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'storage')).toBe(
|
||||
expect(generateAppServiceUrl('test', stagingRegion, 'storage')).toBe(
|
||||
'https://test.storage.eu-west-1.staging.nhost.run/v1',
|
||||
);
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'hasura')).toBe(
|
||||
expect(generateAppServiceUrl('test', stagingRegion, 'hasura')).toBe(
|
||||
'https://test.hasura.eu-west-1.staging.nhost.run',
|
||||
);
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'grafana')).toBe(
|
||||
expect(generateAppServiceUrl('test', stagingRegion, 'grafana')).toBe(
|
||||
'https://test.grafana.eu-west-1.staging.nhost.run',
|
||||
);
|
||||
});
|
||||
|
||||
test('should generate no slug for Hasura and Grafana neither in local mode nor in remote mode', () => {
|
||||
process.env.NEXT_PUBLIC_NHOST_HASURA_API_URL = 'http://localhost:8082';
|
||||
process.env.NEXT_PUBLIC_ENV = 'staging';
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'hasura')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'hasura')).toBe(
|
||||
'http://localhost:8082',
|
||||
);
|
||||
|
||||
process.env.NEXT_PUBLIC_NHOST_PLATFORM = 'true';
|
||||
process.env.NEXT_PUBLIC_ENV = 'staging';
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'hasura')).toBe(
|
||||
expect(generateAppServiceUrl('test', stagingRegion, 'hasura')).toBe(
|
||||
'https://test.hasura.eu-west-1.staging.nhost.run',
|
||||
);
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'grafana')).toBe(
|
||||
expect(generateAppServiceUrl('test', stagingRegion, 'grafana')).toBe(
|
||||
'https://test.grafana.eu-west-1.staging.nhost.run',
|
||||
);
|
||||
|
||||
process.env.NEXT_PUBLIC_ENV = 'production';
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'hasura')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'hasura')).toBe(
|
||||
'https://test.hasura.eu-west-1.nhost.run',
|
||||
);
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'grafana')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'grafana')).toBe(
|
||||
'https://test.grafana.eu-west-1.nhost.run',
|
||||
);
|
||||
});
|
||||
@@ -119,48 +130,45 @@ test('should be able to override the default remote backend slugs', () => {
|
||||
process.env.NEXT_PUBLIC_ENV = 'production';
|
||||
|
||||
expect(
|
||||
generateAppServiceUrl(
|
||||
'test',
|
||||
'eu-west-1',
|
||||
'hasura',
|
||||
defaultLocalBackendSlugs,
|
||||
{ ...defaultRemoteBackendSlugs, hasura: '/lorem-ipsum' },
|
||||
),
|
||||
generateAppServiceUrl('test', region, 'hasura', defaultLocalBackendSlugs, {
|
||||
...defaultRemoteBackendSlugs,
|
||||
hasura: '/lorem-ipsum',
|
||||
}),
|
||||
).toBe('https://test.hasura.eu-west-1.nhost.run/lorem-ipsum');
|
||||
});
|
||||
|
||||
test('should construct service URLs based on environment variables', () => {
|
||||
process.env.NEXT_PUBLIC_NHOST_HASURA_API_URL = 'https://localdev0.nhost.run';
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'hasura')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'hasura')).toBe(
|
||||
`https://localdev0.nhost.run`,
|
||||
);
|
||||
|
||||
process.env.NEXT_PUBLIC_NHOST_AUTH_URL =
|
||||
'https://localdev1.nhost.run/v1/auth';
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'auth')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'auth')).toBe(
|
||||
`https://localdev1.nhost.run/v1/auth`,
|
||||
);
|
||||
|
||||
process.env.NEXT_PUBLIC_NHOST_STORAGE_URL =
|
||||
'https://localdev2.nhost.run/v1/storage';
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'storage')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'storage')).toBe(
|
||||
'https://localdev2.nhost.run/v1/storage',
|
||||
);
|
||||
|
||||
process.env.NEXT_PUBLIC_NHOST_GRAPHQL_URL =
|
||||
'https://localdev3.nhost.run/v1/graphql';
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'graphql')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'graphql')).toBe(
|
||||
'https://localdev3.nhost.run/v1/graphql',
|
||||
);
|
||||
|
||||
process.env.NEXT_PUBLIC_NHOST_FUNCTIONS_URL =
|
||||
'https://localdev4.nhost.run/v1/functions';
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'functions')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'functions')).toBe(
|
||||
'https://localdev4.nhost.run/v1/functions',
|
||||
);
|
||||
});
|
||||
@@ -169,19 +177,19 @@ test('should generate a basic subdomain with a custom port if provided', () => {
|
||||
process.env.NEXT_PUBLIC_NHOST_BACKEND_URL = `http://localhost:1338`;
|
||||
process.env.NEXT_PUBLIC_NHOST_PLATFORM = 'true';
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'auth')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'auth')).toBe(
|
||||
`http://localhost:1338/v1/auth`,
|
||||
);
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'storage')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'storage')).toBe(
|
||||
`http://localhost:1338/v1/files`,
|
||||
);
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'graphql')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'graphql')).toBe(
|
||||
`http://localhost:1338/v1/graphql`,
|
||||
);
|
||||
|
||||
expect(generateAppServiceUrl('test', 'eu-west-1', 'functions')).toBe(
|
||||
expect(generateAppServiceUrl('test', region, 'functions')).toBe(
|
||||
`http://localhost:1338/v1/functions`,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { ProjectFragment } from '@/utils/__generated__/graphql';
|
||||
import {
|
||||
getAuthServiceUrl,
|
||||
getFunctionsServiceUrl,
|
||||
@@ -55,7 +56,7 @@ export const defaultRemoteBackendSlugs: Record<NhostService, string> = {
|
||||
*/
|
||||
export default function generateAppServiceUrl(
|
||||
subdomain: string,
|
||||
region: string,
|
||||
region: ProjectFragment['region'],
|
||||
service: 'auth' | 'graphql' | 'functions' | 'storage' | 'hasura' | 'grafana',
|
||||
localBackendSlugs = defaultLocalBackendSlugs,
|
||||
remoteBackendSlugs = defaultRemoteBackendSlugs,
|
||||
@@ -87,9 +88,14 @@ export default function generateAppServiceUrl(
|
||||
return `${process.env.NEXT_PUBLIC_NHOST_BACKEND_URL}${localBackendSlugs[service]}`;
|
||||
}
|
||||
|
||||
if (process.env.NEXT_PUBLIC_ENV === 'staging') {
|
||||
return `https://${subdomain}.${service}.${region}.staging.nhost.run${remoteBackendSlugs[service]}`;
|
||||
}
|
||||
const constructedDomain = [
|
||||
subdomain,
|
||||
service,
|
||||
region?.awsName,
|
||||
region?.domain || 'nhost.run',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('.');
|
||||
|
||||
return `https://${subdomain}.${service}.${region}.nhost.run${remoteBackendSlugs[service]}`;
|
||||
return `https://${constructedDomain}${remoteBackendSlugs[service]}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user