Skip to content
Snippets Groups Projects
Commit 01a23c83 authored by François Agneray's avatar François Agneray
Browse files

Client config is now provided by server

parent e7799075
No related branches found
No related tags found
1 merge request!29Develop
...@@ -7,12 +7,15 @@ import { Store } from '@ngrx/store'; ...@@ -7,12 +7,15 @@ import { Store } from '@ngrx/store';
import { AppConfigService } from './app-config.service'; import { AppConfigService } from './app-config.service';
import { initializeKeycloak } from 'src/app/auth/init.keycloak'; import { initializeKeycloak } from 'src/app/auth/init.keycloak';
import { environment } from 'src/environments/environment';
function appInit(http: HttpClient, appConfigService: AppConfigService, keycloak: KeycloakService, store: Store<{ }>) { function appInit(http: HttpClient, appConfigService: AppConfigService, keycloak: KeycloakService, store: Store<{ }>) {
return () => { return () => {
return http.get('/assets/app.config.json') return http.get(`${environment.apiUrl}/client-settings`)
.toPromise() .toPromise()
.then(data => { .then(data => {
Object.assign(appConfigService, data); Object.assign(appConfigService, data);
appConfigService.apiUrl = environment.apiUrl;
return appConfigService; return appConfigService;
}) })
.then(appConfigService => { .then(appConfigService => {
......
{
"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
export const environment = { export const environment = {
production: true production: true,
apiUrl: "/server"
}; };
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
// The list of file replacements can be found in `angular.json`. // The list of file replacements can be found in `angular.json`.
export const environment = { export const environment = {
production: false production: false,
apiUrl: "http://localhost:8080"
}; };
/* /*
......
...@@ -29,6 +29,11 @@ services: ...@@ -29,6 +29,11 @@ services:
LOGGER_NAME: "anis-metamodel" LOGGER_NAME: "anis-metamodel"
LOGGER_PATH: "php://stderr" LOGGER_PATH: "php://stderr"
LOGGER_LEVEL: "debug" 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_ENABLED: 0
TOKEN_PUBLIC_KEY_FILE: /mnt/public_key TOKEN_PUBLIC_KEY_FILE: /mnt/public_key
TOKEN_ADMIN_ROLE: anis_admin TOKEN_ADMIN_ROLE: anis_admin
......
...@@ -56,6 +56,10 @@ $container->set('App\Action\RootAction', function () { ...@@ -56,6 +56,10 @@ $container->set('App\Action\RootAction', function () {
return new App\Action\RootAction(); 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) { $container->set('App\Action\SelectListAction', function (ContainerInterface $c) {
return new App\Action\SelectListAction($c->get('em')); return new App\Action\SelectListAction($c->get('em'));
}); });
......
...@@ -13,6 +13,7 @@ declare(strict_types=1); ...@@ -13,6 +13,7 @@ declare(strict_types=1);
use Slim\Routing\RouteCollectorProxy; use Slim\Routing\RouteCollectorProxy;
$app->get('/', App\Action\RootAction::class); $app->get('/', App\Action\RootAction::class);
$app->get('/client-settings', App\Action\ClientSettingsAction::class);
$app->group('', function (RouteCollectorProxy $group) { $app->group('', function (RouteCollectorProxy $group) {
$group->map([OPTIONS, GET, POST], '/select', App\Action\SelectListAction::class); $group->map([OPTIONS, GET, POST], '/select', App\Action\SelectListAction::class);
......
...@@ -31,8 +31,14 @@ return [ ...@@ -31,8 +31,14 @@ return [
'path' => getenv('LOGGER_PATH'), 'path' => getenv('LOGGER_PATH'),
'level' => getenv('LOGGER_LEVEL') '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' => [ 'token' => [
//'issuer' => getenv('TOKEN_ISSUER'),
'enabled' => getenv('TOKEN_ENABLED'), 'enabled' => getenv('TOKEN_ENABLED'),
'public_key_file' => getenv('TOKEN_PUBLIC_KEY_FILE'), 'public_key_file' => getenv('TOKEN_PUBLIC_KEY_FILE'),
'admin_role' => getenv('TOKEN_ADMIN_ROLE') 'admin_role' => getenv('TOKEN_ADMIN_ROLE')
......
<?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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment