Skip to content

Commit

Permalink
chore: use new subdomain and region approach (#124)
Browse files Browse the repository at this point in the history
* chore: update subdomain in config files

* chore: refactor `createNhostServiceEndpoint`
  • Loading branch information
onehassan authored Nov 30, 2023
1 parent 14e5d98 commit 6c1ea86
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/nhost_flutter_auth/example/lib/config.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/// https://github.com/nhost/nhost-dart/#running-the-example-server
const subdomain = 'localhost';
const subdomain = 'local';
const region = '';
2 changes: 1 addition & 1 deletion packages/nhost_flutter_graphql/example/lib/config.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/// https://github.com/nhost/nhost-dart/#running-the-example-server
const subdomain = 'localhost';
const subdomain = 'local';
const region = '';
4 changes: 2 additions & 2 deletions packages/nhost_functions_dart/example/lib/config.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// https://github.com/nhost/nhost-dart/#running-the-example-server
const subdomain = 'localhost:1337';
const subdomain = 'local';
const region = '';
const functionsUrl = 'https://localhost:1337/v1/functions';
const functionsUrl = 'https://local.functions.nhost.run';
2 changes: 1 addition & 1 deletion packages/nhost_graphql_adapter/example/lib/config.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/// https://github.com/nhost/nhost-dart/#running-the-example-server
const subdomain = 'localhost';
const subdomain = 'local';
const region = '';
8 changes: 4 additions & 4 deletions packages/nhost_sdk/lib/src/api/subdomain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ class Subdomain {
/// Project subdomain (e.g. `ieingiwnginwnfnegqwvdqwdwq`)
///
/// Check out nhost dashboard and get your `subdomain`
/// for local development pass 'localhost' or 'localhost:1337'
/// for localhost development pass 'local'
final String subdomain;

/// Project region (e.g. `eu-central-1`)
///
/// Check out nhost dashboard and get your `region`
/// Project region is not required during
/// local development (when `subdomain` is `localhost`)
/// in case of localhost, you pass only empty string ''
/// local development (when `subdomain` is `local`)
/// in case of local, you pass only empty string ''
final String region;

/// When set, the admin secret is sent as a header, `x-hasura-admin-secret`,
///
/// for all requests to GraphQL, Storage, and Serverless Functions.
/// for all requests to GraphQL, Storage, and Functions.
// final String? adminSecret;
}
18 changes: 2 additions & 16 deletions packages/nhost_sdk/lib/src/foundation/uri.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,14 @@ String joinSubpath(String basePath, String subPath) {
return '$path$suffix';
}

/// Generate Endpoint for each service and based on new subdomain approach or
/// override it to localhost for development based on old path-feature
/// Generate Endpoint for each service and based on the subdomain
String createNhostServiceEndpoint({
required String subdomain, // local
required String subdomain,
required String region,
required String service,
String apiVersion = 'v1',
String protocol = 'https',
}) {
final localhostRegex = RegExp(
r'^((?<protocol>http[s]?):\/\/)?(?<host>localhost)(:(?<port>(\d+|__\w+__)))?$',
);

// checking for local development environment
if (localhostRegex.hasMatch(subdomain)) {
final hasPort = subdomain.split(':').length == 2;
if (hasPort) {
return 'http://$subdomain/$apiVersion/$service';
}
return 'http://$subdomain:1337/$apiVersion/$service';
}

if (region.isEmpty && subdomain == 'local') {
return '$protocol://$subdomain.$service.nhost.run/$apiVersion';
}
Expand Down
6 changes: 3 additions & 3 deletions packages/nhost_storage_dart/example/lib/config.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:nhost_auth_dart/nhost_auth_dart.dart';

/// https://github.com/nhost/nhost-dart/#running-the-example-server
const subdomain = 'localhost:1337';
const subdomain = 'local';
const region = '';
const authUrl = 'https://localhost:1337/v1/auth';
const storageUrl = 'https://localhost:1337/v1/storage';
const authUrl = 'https://local.auth.nhost.run';
const storageUrl = 'https://local.storage.nhost.run';

Future<void> signInOrSignUp(
NhostAuthClient nhostAuthClient, {
Expand Down

0 comments on commit 6c1ea86

Please sign in to comment.