Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: enable debug with localhost (#4058)

Nathan.foooafab3d5374de
diff --git a/frontend/.vscode/tasks.json b/frontend/.vscode/tasks.json
index b2a3f1b66c..1177df2a0a 100644
--- a/frontend/.vscode/tasks.json
+++ b/frontend/.vscode/tasks.json
@@ -14,7 +14,6 @@
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
- "AF: Dart Clean",
"AF: Flutter Clean",
"AF: Build Appflowy Core",
"AF: Flutter Pub Get",
@@ -33,7 +32,6 @@
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
- "AF: Dart Clean",
"AF: Flutter Clean",
"AF: Build Appflowy Core For iOS",
"AF: Flutter Pub Get",
@@ -52,7 +50,6 @@
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
- "AF: Dart Clean",
"AF: Flutter Clean",
"AF: Build Appflowy Core For iOS Simulator",
"AF: Flutter Pub Get",
@@ -89,7 +86,6 @@
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
- "AF: Dart Clean",
"AF: Flutter Clean",
"AF: Build Appflowy Core For Android",
"AF: Flutter Pub Get",
diff --git a/frontend/appflowy_flutter/lib/env/cloud_env.dart b/frontend/appflowy_flutter/lib/env/cloud_env.dart
index 6b98cb026b..411f670283 100644
--- a/frontend/appflowy_flutter/lib/env/cloud_env.dart
+++ b/frontend/appflowy_flutter/lib/env/cloud_env.dart
@@ -186,6 +186,7 @@ class AppFlowyCloudSharedEnv {
AuthenticatorType get authenticatorType => _authenticatorType;
static Future<AppFlowyCloudSharedEnv> fromEnv() async {
+ // If [Env.enableCustomCloud] is true, then use the custom cloud configuration.
if (Env.enableCustomCloud) {
// Use the custom cloud configuration.
final cloudType = await getAuthenticatorType();
@@ -198,6 +199,7 @@ class AppFlowyCloudSharedEnv {
supabaseConfig: supabaseCloudConfig,
);
} else {
+ // Using the cloud settings from the .env file.
final appflowyCloudConfig = AppFlowyCloudConfiguration(
base_url: Env.afCloudUrl,
ws_base_url: await _getAppFlowyCloudWSUrl(Env.afCloudUrl),
@@ -213,13 +215,36 @@ class AppFlowyCloudSharedEnv {
}
}
+Future<AppFlowyCloudConfiguration> configurationFromUri(
+ Uri baseUri,
+ String baseUrl,
+) async {
+// When the host is set to 'localhost', the application will utilize the local configuration. This setup assumes that 'localhost' does not employ a reverse proxy, therefore default port settings are used.
+ if (baseUri.host == "localhost") {
+ return AppFlowyCloudConfiguration(
+ base_url: "$baseUrl:8000",
+ ws_base_url: "ws://${baseUri.host}:8000/ws",
+ gotrue_url: "$baseUrl:9998",
+ );
+ } else {
+ return AppFlowyCloudConfiguration(
+ base_url: baseUrl,
+ ws_base_url: await _getAppFlowyCloudWSUrl(Env.afCloudUrl),
+ gotrue_url: await _getAppFlowyCloudGotrueUrl(Env.afCloudUrl),
+ );
+ }
+}
+
Future<AppFlowyCloudConfiguration> getAppFlowyCloudConfig() async {
final baseURL = await getAppFlowyCloudUrl();
- return AppFlowyCloudConfiguration(
- base_url: baseURL,
- ws_base_url: await _getAppFlowyCloudWSUrl(baseURL),
- gotrue_url: await _getAppFlowyCloudGotrueUrl(baseURL),
- );
+
+ try {
+ final uri = Uri.parse(baseURL);
+ return await configurationFromUri(uri, baseURL);
+ } catch (e) {
+ Log.error("Failed to parse AppFlowy Cloud URL: $e");
+ return AppFlowyCloudConfiguration.defaultConfig();
+ }
}
Future<String> getAppFlowyCloudUrl() async {
diff --git a/frontend/appflowy_flutter/lib/env/env.dart b/frontend/appflowy_flutter/lib/env/env.dart
index 6444ee6a0f..1f9884ef76 100644
--- a/frontend/appflowy_flutter/lib/env/env.dart
+++ b/frontend/appflowy_flutter/lib/env/env.dart
@@ -6,6 +6,7 @@ part 'env.g.dart';
@Envied(path: '.env')
abstract class Env {
+ // This flag is used to decide if users can dynamically configure cloud settings. It turns true when a .env file exists containing the APPFLOWY_CLOUD_URL variable. By default, this is set to false.
static bool get enableCustomCloud {
return Env.authenticatorType == AuthenticatorType.appflowyCloud.value &&
_Env.afCloudUrl.isEmpty;
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart
index 42ccd86552..7763222d3e 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart
@@ -44,24 +44,33 @@ class SettingAppFlowyCloudView extends StatelessWidget {
BlocProvider<AppFlowyCloudSettingBloc> _renderContent(
CloudSettingPB setting,
) {
+ final List<Widget> children = [];
+ children.addAll([
+ const AppFlowyCloudEnableSync(),
+ const VSpace(40),
+ ]);
+
+ // If the enableCustomCloud flag is true, then the user can dynamically configure cloud settings. Otherwise, the user cannot dynamically configure cloud settings.
+ if (Env.enableCustomCloud) {
+ children.add(
+ AppFlowyCloudURLs(didUpdateUrls: () => didResetServerUrl()),
+ );
+ } else {
+ children.add(
+ Row(
+ children: [
+ FlowyText(LocaleKeys.settings_menu_cloudServerType.tr()),
+ const Spacer(),
+ const FlowyText(Env.afCloudUrl),
+ ],
+ ),
+ );
+ }
return BlocProvider(
create: (context) => AppFlowyCloudSettingBloc(setting)
..add(const AppFlowyCloudSettingEvent.initial()),
child: Column(
- children: [
- const AppFlowyCloudEnableSync(),
- const VSpace(40),
- if (Env.enableCustomCloud)
- AppFlowyCloudURLs(didUpdateUrls: () => didResetServerUrl()),
- if (!Env.enableCustomCloud)
- Row(
- children: [
- FlowyText(LocaleKeys.settings_menu_cloudServerType.tr()),
- const Spacer(),
- const FlowyText(Env.afCloudUrl),
- ],
- ),
- ],
+ children: children,
),
);
}