This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
routes.dart
to automatically configure root url
- Loading branch information
1 parent
2156e6a
commit c6de460
Showing
3 changed files
with
51 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,42 @@ | ||
// ignore_for_file: constant_identifier_names | ||
import 'dart:io'; | ||
|
||
class AppConfig { | ||
AppConfig._(); // Private constructor | ||
|
||
// Determine the root URL based on the platform | ||
// Used for development only. Once the api is deployed, this can be ignored. | ||
static String get _rootUrl { | ||
if (Platform.isAndroid) { | ||
return 'http://10.0.2.2:8081/api'; | ||
} else if (Platform.isIOS) { | ||
return 'http://localhost:8081/api'; | ||
} | ||
throw UnsupportedError('Unsupported platform'); | ||
} | ||
|
||
// AUTHENTICATION | ||
static String get basicAuthUrl => | ||
'${_rootUrl.replaceFirst('/api', '')}/login'; | ||
static String get ssoAuthUrl => 'https://live.rbg.tum.de/saml/out'; | ||
static String get ssoRedirectUrl => 'https://live.rbg.tum.de'; | ||
|
||
// NOTE: 10.0.2.2 is the android emulator's alias for the loopback address on | ||
// the host machine. On iOS, use either localhost or the actual IP address | ||
// of the host machine. | ||
|
||
// API ROOT URL | ||
const _ROOT_URL = 'http://10.0.2.2:8081/api'; | ||
const _GRPC_HOST = '10.0.2.2'; | ||
const _GRPC_PORT = 12544; | ||
|
||
// AUTHENTICATION | ||
const _BASIC_AUTH_URL = 'http://10.0.2.2:8081/login'; | ||
const _SSO_AUTH_URL = 'https://live.rbg.tum.de/saml/out'; | ||
const _SSO_REDIRECT_URL = 'https://live.rbg.tum.de'; | ||
|
||
// COURSES | ||
const _COURSES_PATH = '/courses'; | ||
const _COURSES_LIVE_PATH = '/courses/live'; | ||
const _COURSES_USER_PATH = '/courses/user'; | ||
const _COURSES_USER_PINNED_PATH = '/courses/user/pinned'; | ||
const _COURSES_PUBLIC_PATH = '/courses/public'; | ||
|
||
// SEMESTERS | ||
const _SEMESTERS_PATH = '/semesters'; | ||
// gRPC routes | ||
static String get grpcHost { | ||
return Platform.isAndroid | ||
? '10.0.2.2' | ||
: 'localhost'; // Or host machine IP for iOS | ||
} | ||
|
||
// USER AND SERVER NOTIFICATIONS | ||
const _NOTIFICATIONS_USER_PATH = '/notifications'; | ||
const _NOTIFICATIONS_SERVER_PATH = '/notifications/server'; | ||
static const int grpcPort = 12544; | ||
} | ||
|
||
class Routes { | ||
// HTTP routes | ||
static const basicLogin = _BASIC_AUTH_URL; | ||
static const ssoLogin = _SSO_AUTH_URL; | ||
static const ssoRedirect = _SSO_REDIRECT_URL; | ||
static const courses = _ROOT_URL + _COURSES_PATH; | ||
static const coursesLive = _ROOT_URL + _COURSES_LIVE_PATH; | ||
static const coursesUser = _ROOT_URL + _COURSES_USER_PATH; | ||
static const coursesUserPinned = _ROOT_URL + _COURSES_USER_PINNED_PATH; | ||
static const coursesPublic = _ROOT_URL + _COURSES_PUBLIC_PATH; | ||
static const semesters = _ROOT_URL + _SEMESTERS_PATH; | ||
static const notificationsUser = _ROOT_URL + _NOTIFICATIONS_USER_PATH; | ||
static const notificationsServer = _ROOT_URL + _NOTIFICATIONS_SERVER_PATH; | ||
static String get basicLogin => AppConfig.basicAuthUrl; | ||
static String get ssoLogin => AppConfig.ssoAuthUrl; | ||
static String get ssoRedirect => AppConfig.ssoRedirectUrl; | ||
|
||
// gRPC routes | ||
static const grpcHost = _GRPC_HOST; | ||
static const grpcPort = _GRPC_PORT; | ||
// gRPC config | ||
static String get grpcHost => AppConfig.grpcHost; | ||
static const int grpcPort = AppConfig.grpcPort; | ||
} |