diff --git a/client/src/app/app-init.ts b/client/src/app/app-init.ts index b3dc042681bc40d7d903a4e8585e2349fdff7613..6b9241ee9afd93090d03991dda756a79062137d4 100644 --- a/client/src/app/app-init.ts +++ b/client/src/app/app-init.ts @@ -7,12 +7,15 @@ import { Store } from '@ngrx/store'; import { AppConfigService } from './app-config.service'; import { initializeKeycloak } from 'src/app/auth/init.keycloak'; +import { environment } from 'src/environments/environment'; + function appInit(http: HttpClient, appConfigService: AppConfigService, keycloak: KeycloakService, store: Store<{ }>) { return () => { - return http.get('/assets/app.config.json') + return http.get(`${environment.apiUrl}/client-settings`) .toPromise() .then(data => { Object.assign(appConfigService, data); + appConfigService.apiUrl = environment.apiUrl; return appConfigService; }) .then(appConfigService => { diff --git a/client/src/assets/app.config.json b/client/src/assets/app.config.json deleted file mode 100644 index 69f72dd76e9f151588ed89265dd996fff407414e..0000000000000000000000000000000000000000 --- a/client/src/assets/app.config.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "apiUrl": "http://localhost:8080", - "servicesUrl": "http://localhost:5000", - "baseHref": "/", - "authenticationEnabled": false, - "ssoAuthUrl": "http://localhost:8180/auth", - "ssoRealm": "anis", - "ssoClientId": "anis-client", - "adminRole": "anis_admin" -} \ No newline at end of file diff --git a/client/src/environments/environment.prod.ts b/client/src/environments/environment.prod.ts index 5d0833162027e2147e99e72a1a94bb7d3cb62843..5506fedd9829d17697569af187d24a95a4184af4 100644 --- a/client/src/environments/environment.prod.ts +++ b/client/src/environments/environment.prod.ts @@ -1,3 +1,4 @@ export const environment = { - production: true + production: true, + apiUrl: "/server" }; diff --git a/client/src/environments/environment.ts b/client/src/environments/environment.ts index 458476a4df52c64d1a2abee43c6cb91d87abad77..0a202e32320026491d3fdbf7ea375cea6ac5a2cf 100644 --- a/client/src/environments/environment.ts +++ b/client/src/environments/environment.ts @@ -3,7 +3,8 @@ // The list of file replacements can be found in `angular.json`. export const environment = { - production: false + production: false, + apiUrl: "http://localhost:8080" }; /* diff --git a/docker-compose.yml b/docker-compose.yml index bc9bd7b06cecef4ee1d3fbb01266056a56649ce1..ee412b76725a54d72cfad75ec8636d000a5842f9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,6 +29,11 @@ services: LOGGER_NAME: "anis-metamodel" LOGGER_PATH: "php://stderr" LOGGER_LEVEL: "debug" + SERVICES_URL: "http://localhost:5000" + BASE_HREF: "/" + SSO_AUTH_URL: "http://localhost:8180/auth" + SSO_REALM: "anis" + SSO_CLIENT_ID: "anis-client" TOKEN_ENABLED: 0 TOKEN_PUBLIC_KEY_FILE: /mnt/public_key TOKEN_ADMIN_ROLE: anis_admin diff --git a/server/app/dependencies.php b/server/app/dependencies.php index 654451c818e6c69cb6fb569e6fec9378b4ac50f1..2ba1d1681c1f8c71cb792a2c0ff90614ef782108 100644 --- a/server/app/dependencies.php +++ b/server/app/dependencies.php @@ -56,6 +56,10 @@ $container->set('App\Action\RootAction', function () { return new App\Action\RootAction(); }); +$container->set('App\Action\ClientSettingsAction', function (ContainerInterface $c) { + return new App\Action\ClientSettingsAction($c->get(SETTINGS)); +}); + $container->set('App\Action\SelectListAction', function (ContainerInterface $c) { return new App\Action\SelectListAction($c->get('em')); }); diff --git a/server/app/routes.php b/server/app/routes.php index 0c8d278c44c4ae5d5bad542b3d103ca948f6825c..42b9479b79dc9da018607214cc06690a32bfe7dc 100644 --- a/server/app/routes.php +++ b/server/app/routes.php @@ -13,6 +13,7 @@ declare(strict_types=1); use Slim\Routing\RouteCollectorProxy; $app->get('/', App\Action\RootAction::class); +$app->get('/client-settings', App\Action\ClientSettingsAction::class); $app->group('', function (RouteCollectorProxy $group) { $group->map([OPTIONS, GET, POST], '/select', App\Action\SelectListAction::class); diff --git a/server/app/settings.php b/server/app/settings.php index a37c755705f852b00796fabacbd0b66aaf054099..f018b5675ac88559c6948d89061be79ee73f8acb 100644 --- a/server/app/settings.php +++ b/server/app/settings.php @@ -31,8 +31,14 @@ return [ 'path' => getenv('LOGGER_PATH'), 'level' => getenv('LOGGER_LEVEL') ], + 'services_url' => getenv('SERVICES_URL'), + 'base_href' => getenv('BASE_HREF'), + 'sso' => [ + 'auth_url' => getenv('SSO_AUTH_URL'), + 'realm' => getenv('SSO_REALM'), + 'client_id' => getenv('SSO_CLIENT_ID') + ], 'token' => [ - //'issuer' => getenv('TOKEN_ISSUER'), 'enabled' => getenv('TOKEN_ENABLED'), 'public_key_file' => getenv('TOKEN_PUBLIC_KEY_FILE'), 'admin_role' => getenv('TOKEN_ADMIN_ROLE') diff --git a/server/src/Action/ClientSettingsAction.php b/server/src/Action/ClientSettingsAction.php new file mode 100644 index 0000000000000000000000000000000000000000..1018ac39d0a8853cd63592936b6a385b00218ac8 --- /dev/null +++ b/server/src/Action/ClientSettingsAction.php @@ -0,0 +1,61 @@ +<?php + +/* + * This file is part of Anis Server. + * + * (c) Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +declare(strict_types=1); + +namespace App\Action; + +use Psr\Http\Message\ResponseInterface as Response; +use Psr\Http\Message\ServerRequestInterface as Request; + +/** + * Client settings action + * + * @author François Agneray <francois.agneray@lam.fr> + * @package App\Action + */ +final class ClientSettingsAction +{ + /** + * The ANIS settings array + * + * @var array + */ + private $settings; + + public function __construct($settings) + { + $this->settings = $settings; + } + + /** + * This action indicates that the service is responding + * + * @param ServerRequestInterface $request PSR-7 This object represents the HTTP request + * @param ResponseInterface $response PSR-7 This object represents the HTTP response + * @param string[] $args This table contains information transmitted in the URL (see routes.php) + * + * @return ResponseInterface + */ + public function __invoke(Request $request, Response $response, array $args): Response + { + $payload = json_encode(array( + 'servicesUrl' => $this->settings['services_url'], + 'baseHref' => $this->settings['base_href'], + 'authenticationEnabled' => boolval($this->settings['token']['enabled']), + 'ssoAuthUrl' => $this->settings['sso']['auth_url'], + 'ssoRealm' => $this->settings['sso']['realm'], + 'ssoClientId' => $this->settings['sso']['client_id'], + 'adminRole' => $this->settings['token']['admin_role'] + )); + $response->getBody()->write($payload); + return $response; + } +}